diff --git a/gateway-contracts/test/CiphertextCommits.ts b/gateway-contracts/test/CiphertextCommits.ts index 1b8287cbac..0731283bd5 100644 --- a/gateway-contracts/test/CiphertextCommits.ts +++ b/gateway-contracts/test/CiphertextCommits.ts @@ -4,7 +4,7 @@ import { expect } from "chai"; import { Wallet } from "ethers"; import hre from "hardhat"; -import { CiphertextCommits, CiphertextCommits__factory, GatewayConfig } from "../typechain-types"; +import { CiphertextCommits, CiphertextCommits__factory } from "../typechain-types"; import { createBytes32, createCtHandle, @@ -37,11 +37,9 @@ describe("CiphertextCommits", function () { const fakeTxSender = createRandomWallet(); const fakeCiphertextDigest = createBytes32(); - let gatewayConfig: GatewayConfig; let ciphertextCommits: CiphertextCommits; let coprocessorTxSenders: HardhatEthersSigner[]; let owner: Wallet; - let pauser: Wallet; async function prepareFixture() { const fixtureData = await loadFixture(loadTestVariablesFixture); @@ -69,11 +67,9 @@ describe("CiphertextCommits", function () { beforeEach(async function () { // Initialize globally used variables before each test const fixture = await loadFixture(prepareFixture); - gatewayConfig = fixture.gatewayConfig; coprocessorTxSenders = fixture.coprocessorTxSenders; ciphertextCommits = fixture.ciphertextCommits; owner = fixture.owner; - pauser = fixture.pauser; }); describe("Deployment", function () { diff --git a/gateway-contracts/test/Decryption.ts b/gateway-contracts/test/Decryption.ts index 28c1506468..15f16d04ff 100644 --- a/gateway-contracts/test/Decryption.ts +++ b/gateway-contracts/test/Decryption.ts @@ -106,24 +106,6 @@ describe("Decryption", function () { // Define extra data for version 0 const extraDataV0 = hre.ethers.solidityPacked(["uint8"], [0]); - let ciphertextCommits: CiphertextCommits; - let decryption: Decryption; - let protocolPayment: ProtocolPayment; - let mockedZamaOFT: ZamaOFT; - let owner: Wallet; - let pauser: Wallet; - let snsCiphertextMaterials: SnsCiphertextMaterialStruct[]; - let kmsSignatures: string[]; - let kmsTxSenders: HardhatEthersSigner[]; - let kmsSigners: HardhatEthersSigner[]; - let coprocessorTxSenders: HardhatEthersSigner[]; - let publicDecryptionPrice: bigint; - let userDecryptionPrice: bigint; - let tokenFundedTxSender: Wallet; - let protocolPaymentAddress: string; - let decryptionAddress: string; - let mockedFeesSenderToBurnerAddress: string; - // Add ciphertext materials async function prepareAddCiphertextFixture() { const fixtureData = await loadFixture(loadTestVariablesFixture); @@ -152,6 +134,8 @@ describe("Decryption", function () { } describe("Deployment", function () { + let decryption: Decryption; + let owner: Wallet; let decryptionFactory: Decryption__factory; beforeEach(async function () { @@ -173,6 +157,21 @@ describe("Decryption", function () { }); describe("Public Decryption", function () { + let ciphertextCommits: CiphertextCommits; + let decryption: Decryption; + let protocolPayment: ProtocolPayment; + let mockedZamaOFT: ZamaOFT; + let pauser: Wallet; + let snsCiphertextMaterials: SnsCiphertextMaterialStruct[]; + let kmsSignatures: string[]; + let kmsTxSenders: HardhatEthersSigner[]; + let kmsSigners: HardhatEthersSigner[]; + let coprocessorTxSenders: HardhatEthersSigner[]; + let publicDecryptionPrice: bigint; + let tokenFundedTxSender: Wallet; + let protocolPaymentAddress: string; + let decryptionAddress: string; + let mockedFeesSenderToBurnerAddress: string; let eip712Message: EIP712; // Expected decryption request ID (after a first request) for a public decryption request @@ -215,7 +214,6 @@ describe("Decryption", function () { protocolPayment = fixtureData.protocolPayment; mockedZamaOFT = fixtureData.mockedZamaOFT; mockedFeesSenderToBurnerAddress = fixtureData.mockedFeesSenderToBurnerAddress; - owner = fixtureData.owner; pauser = fixtureData.pauser; snsCiphertextMaterials = fixtureData.snsCiphertextMaterials; kmsSignatures = fixtureData.kmsSignatures; @@ -225,7 +223,6 @@ describe("Decryption", function () { eip712Message = fixtureData.eip712Message; decryptionAddress = fixtureData.decryptionAddress; publicDecryptionPrice = fixtureData.publicDecryptionPrice; - userDecryptionPrice = fixtureData.userDecryptionPrice; tokenFundedTxSender = fixtureData.tokenFundedTxSender; protocolPaymentAddress = await protocolPayment.getAddress(); @@ -679,6 +676,21 @@ describe("Decryption", function () { }); describe("User Decryption", function () { + let ciphertextCommits: CiphertextCommits; + let decryption: Decryption; + let protocolPayment: ProtocolPayment; + let mockedZamaOFT: ZamaOFT; + let pauser: Wallet; + let snsCiphertextMaterials: SnsCiphertextMaterialStruct[]; + let kmsSignatures: string[]; + let kmsTxSenders: HardhatEthersSigner[]; + let kmsSigners: HardhatEthersSigner[]; + let coprocessorTxSenders: HardhatEthersSigner[]; + let userDecryptionPrice: bigint; + let tokenFundedTxSender: Wallet; + let protocolPaymentAddress: string; + let decryptionAddress: string; + let mockedFeesSenderToBurnerAddress: string; let userSignature: string; let userDecryptedShares: string[]; let eip712RequestMessage: EIP712; @@ -717,15 +729,7 @@ describe("Decryption", function () { }; // Define fake values - const fakeUserAddress = createRandomAddress(); const fakeContractAddresses = createRandomAddresses(3); - const fakeContractAddress = fakeContractAddresses[0]; - const fakeContractAddressCtHandleContractPairs: CtHandleContractPairStruct[] = [ - { - contractAddress: fakeContractAddress, - ctHandle, - }, - ]; // Define utility values const tenDaysInSeconds = 10 * 24 * 60 * 60; @@ -785,7 +789,7 @@ describe("Decryption", function () { decryption = fixtureData.decryption; protocolPayment = fixtureData.protocolPayment; mockedZamaOFT = fixtureData.mockedZamaOFT; - owner = fixtureData.owner; + mockedFeesSenderToBurnerAddress = fixtureData.mockedFeesSenderToBurnerAddress; pauser = fixtureData.pauser; snsCiphertextMaterials = fixtureData.snsCiphertextMaterials; userSignature = fixtureData.userSignature; @@ -797,7 +801,6 @@ describe("Decryption", function () { eip712RequestMessage = fixtureData.eip712RequestMessage; eip712ResponseMessages = fixtureData.eip712ResponseMessages; decryptionAddress = fixtureData.decryptionAddress; - publicDecryptionPrice = fixtureData.publicDecryptionPrice; userDecryptionPrice = fixtureData.userDecryptionPrice; tokenFundedTxSender = fixtureData.tokenFundedTxSender; @@ -1636,6 +1639,19 @@ describe("Decryption", function () { }); describe("Delegated User Decryption", function () { + let ciphertextCommits: CiphertextCommits; + let decryption: Decryption; + let protocolPayment: ProtocolPayment; + let mockedZamaOFT: ZamaOFT; + let pauser: Wallet; + let snsCiphertextMaterials: SnsCiphertextMaterialStruct[]; + let kmsSignatures: string[]; + let kmsTxSenders: HardhatEthersSigner[]; + let coprocessorTxSenders: HardhatEthersSigner[]; + let userDecryptionPrice: bigint; + let tokenFundedTxSender: Wallet; + let protocolPaymentAddress: string; + let mockedFeesSenderToBurnerAddress: string; let delegateSignature: string; let userDecryptedShares: string[]; let eip712RequestMessage: EIP712; @@ -1680,19 +1696,7 @@ describe("Decryption", function () { }; // Define fake values. - const fakeDelegatorAddress = createRandomAddress(); const fakeContractAddresses = createRandomAddresses(3); - const fakeContractAddress = fakeContractAddresses[0]; - const fakeContractAddressCtHandleContractPairs: CtHandleContractPairStruct[] = [ - { - contractAddress: fakeContractAddress, - ctHandle, - }, - ]; - const fakeDelegatorDelegationAccounts: IDecryption.DelegationAccountsStruct = { - delegatorAddress: fakeDelegatorAddress, - delegateAddress, - }; // Define utility values. const tenDaysInSeconds = 10 * 24 * 60 * 60; @@ -1754,7 +1758,6 @@ describe("Decryption", function () { protocolPayment = fixtureData.protocolPayment; mockedZamaOFT = fixtureData.mockedZamaOFT; mockedFeesSenderToBurnerAddress = fixtureData.mockedFeesSenderToBurnerAddress; - owner = fixtureData.owner; pauser = fixtureData.pauser; snsCiphertextMaterials = fixtureData.snsCiphertextMaterials; delegateSignature = fixtureData.delegateSignature; @@ -2428,6 +2431,10 @@ describe("Decryption", function () { }); describe("Pause", async function () { + let decryption: Decryption; + let owner: Wallet; + let pauser: Wallet; + beforeEach(async function () { const fixtureData = await loadFixture(loadTestVariablesFixture); decryption = fixtureData.decryption; diff --git a/gateway-contracts/test/GatewayConfig.ts b/gateway-contracts/test/GatewayConfig.ts index 66a53482c5..e40be1373a 100644 --- a/gateway-contracts/test/GatewayConfig.ts +++ b/gateway-contracts/test/GatewayConfig.ts @@ -58,26 +58,6 @@ describe("GatewayConfig", function () { const fakeTxSender = createRandomWallet(); const fakeSigner = createRandomWallet(); - let gatewayConfig: GatewayConfig; - let owner: Wallet; - let pauser: Wallet; - let nKmsNodes: number; - let kmsNodes: KmsNodeStruct[]; - let kmsTxSenders: HardhatEthersSigner[]; - let kmsSigners: HardhatEthersSigner[]; - let coprocessors: CoprocessorStruct[]; - let nCoprocessors: number; - let coprocessorTxSenders: HardhatEthersSigner[]; - let coprocessorSigners: HardhatEthersSigner[]; - let custodians: CustodianStruct[]; - let custodianTxSenders: HardhatEthersSigner[]; - let custodianSigners: HardhatEthersSigner[]; - let highMpcThreshold: number; - let highPublicDecryptionThreshold: number; - let highUserDecryptionThreshold: number; - let highKmsGenThreshold: number; - let highCoprocessorThreshold: number; - async function getInputsForDeployFixture() { const fixtureData = await loadFixture(loadTestVariablesFixture); const { @@ -97,7 +77,7 @@ describe("GatewayConfig", function () { } = fixtureData; // Create KMS nodes with the tx sender and signer addresses - kmsNodes = []; + const kmsNodes: KmsNodeStruct[] = []; for (let i = 0; i < nKmsNodes; i++) { kmsNodes.push({ txSenderAddress: kmsTxSenders[i].address, @@ -108,7 +88,7 @@ describe("GatewayConfig", function () { } // Create coprocessors with the tx sender and signer addresses - coprocessors = []; + const coprocessors: CoprocessorStruct[] = []; for (let i = 0; i < nCoprocessors; i++) { coprocessors.push({ txSenderAddress: coprocessorTxSenders[i].address, @@ -118,7 +98,7 @@ describe("GatewayConfig", function () { } // Create custodians with the tx sender addresses - custodians = []; + const custodians: CustodianStruct[] = []; for (let i = 0; i < nCustodians; i++) { custodians.push({ txSenderAddress: custodianTxSenders[i].address, @@ -127,34 +107,42 @@ describe("GatewayConfig", function () { }); } - return fixtureData; + return { ...fixtureData, kmsNodes, coprocessors, custodians }; } - before(async function () { - // Initialize globally used variables before each test - const fixtureData = await loadFixture(getInputsForDeployFixture); - gatewayConfig = fixtureData.gatewayConfig; - owner = fixtureData.owner; - pauser = fixtureData.pauser; - nKmsNodes = fixtureData.nKmsNodes; - kmsTxSenders = fixtureData.kmsTxSenders; - kmsSigners = fixtureData.kmsSigners; - nCoprocessors = fixtureData.nCoprocessors; - coprocessorTxSenders = fixtureData.coprocessorTxSenders; - coprocessorSigners = fixtureData.coprocessorSigners; - - highMpcThreshold = nKmsNodes; - highPublicDecryptionThreshold = nKmsNodes + 1; - highUserDecryptionThreshold = nKmsNodes + 1; - highKmsGenThreshold = nKmsNodes + 1; - highCoprocessorThreshold = nCoprocessors + 1; - }); - describe("Deployment", function () { + let gatewayConfig: GatewayConfig; + let owner: Wallet; + let kmsNodes: KmsNodeStruct[]; + let coprocessors: CoprocessorStruct[]; + let custodians: CustodianStruct[]; + let nKmsNodes: number; + let nCoprocessors: number; + let highMpcThreshold: number; + let highPublicDecryptionThreshold: number; + let highUserDecryptionThreshold: number; + let highKmsGenThreshold: number; + let highCoprocessorThreshold: number; let proxyContract: EmptyUUPSProxyGatewayConfig; let newGatewayConfigFactory: ContractFactory; beforeEach(async function () { + // Load fixture data locally + const fixtureData = await loadFixture(getInputsForDeployFixture); + gatewayConfig = fixtureData.gatewayConfig; + owner = fixtureData.owner; + kmsNodes = fixtureData.kmsNodes; + coprocessors = fixtureData.coprocessors; + custodians = fixtureData.custodians; + nKmsNodes = fixtureData.nKmsNodes; + nCoprocessors = fixtureData.nCoprocessors; + + highMpcThreshold = nKmsNodes; + highPublicDecryptionThreshold = nKmsNodes + 1; + highUserDecryptionThreshold = nKmsNodes + 1; + highKmsGenThreshold = nKmsNodes + 1; + highCoprocessorThreshold = nCoprocessors + 1; + // Deploy a new proxy contract for the GatewayConfig contract const proxyImplementation = await hre.ethers.getContractFactory("EmptyUUPSProxyGatewayConfig", owner); proxyContract = await hre.upgrades.deployProxy(proxyImplementation, [owner.address], { @@ -570,15 +558,48 @@ describe("GatewayConfig", function () { }); describe("After deployment", function () { + let gatewayConfig: GatewayConfig; + let owner: Wallet; + let pauser: Wallet; + let nKmsNodes: number; + let kmsNodes: KmsNodeStruct[]; + let kmsTxSenders: HardhatEthersSigner[]; + let kmsSigners: HardhatEthersSigner[]; + let nCoprocessors: number; + let coprocessors: CoprocessorStruct[]; + let coprocessorTxSenders: HardhatEthersSigner[]; + let coprocessorSigners: HardhatEthersSigner[]; + let custodians: CustodianStruct[]; + let custodianTxSenders: HardhatEthersSigner[]; + let custodianSigners: HardhatEthersSigner[]; + let highMpcThreshold: number; + let highPublicDecryptionThreshold: number; + let highUserDecryptionThreshold: number; + let highKmsGenThreshold: number; + let highCoprocessorThreshold: number; + beforeEach(async function () { - const fixture = await loadFixture(loadTestVariablesFixture); + const fixture = await loadFixture(getInputsForDeployFixture); gatewayConfig = fixture.gatewayConfig; + owner = fixture.owner; pauser = fixture.pauser; + nKmsNodes = fixture.nKmsNodes; + kmsNodes = fixture.kmsNodes; kmsTxSenders = fixture.kmsTxSenders; kmsSigners = fixture.kmsSigners; + nCoprocessors = fixture.nCoprocessors; + coprocessors = fixture.coprocessors; coprocessorTxSenders = fixture.coprocessorTxSenders; + coprocessorSigners = fixture.coprocessorSigners; + custodians = fixture.custodians; custodianTxSenders = fixture.custodianTxSenders; custodianSigners = fixture.custodianSigners; + + highMpcThreshold = nKmsNodes; + highPublicDecryptionThreshold = nKmsNodes + 1; + highUserDecryptionThreshold = nKmsNodes + 1; + highKmsGenThreshold = nKmsNodes + 1; + highCoprocessorThreshold = nCoprocessors + 1; }); describe("Operators updates", function () { @@ -1454,6 +1475,10 @@ describe("GatewayConfig", function () { }); describe("Pause", async function () { + let gatewayConfig: GatewayConfig; + let owner: Wallet; + let pauser: Wallet; + const fakeOwner = createRandomWallet(); const fakePauser = createRandomWallet(); diff --git a/gateway-contracts/test/KMSGeneration.ts b/gateway-contracts/test/KMSGeneration.ts index 3726df6f56..a3c1ca8785 100644 --- a/gateway-contracts/test/KMSGeneration.ts +++ b/gateway-contracts/test/KMSGeneration.ts @@ -134,13 +134,9 @@ describe("KMSGeneration", function () { // Define a fake values. const fakeOwner = createRandomWallet(); - let kmsGeneration: KMSGeneration; - let owner: Wallet; - let kmsTxSenders: HardhatEthersSigner[]; - let kmsSigners: HardhatEthersSigner[]; - let kmsNodeStorageUrls: string[]; - describe("Deployment", function () { + let kmsGeneration: KMSGeneration; + let owner: Wallet; let kmsGenerationFactory: KMSGeneration__factory; beforeEach(async function () { @@ -174,6 +170,8 @@ describe("KMSGeneration", function () { const keyDigests = [serverKeyDigest, publicKeyDigest]; describe("Before key generation", function () { + let kmsGeneration: KMSGeneration; + // Define a fake key ID. const fakeKeyId = getKeyId(1); @@ -225,8 +223,12 @@ describe("KMSGeneration", function () { // Define the expected prepKeygenId. const prepKeygenId = getPrepKeygenId(1); - let kmsGenerationAddress: string; + let kmsGeneration: KMSGeneration; + let owner: Wallet; + let kmsTxSenders: HardhatEthersSigner[]; let kmsSigners: HardhatEthersSigner[]; + let kmsNodeStorageUrls: string[]; + let kmsGenerationAddress: string; let eip712MessagePrepKeygen: EIP712; let kmsSignaturesPrepKeygen: string[]; let eip712MessageKeygen: EIP712; @@ -426,6 +428,11 @@ describe("KMSGeneration", function () { }); describe("After key generation", function () { + let kmsGeneration: KMSGeneration; + let owner: Wallet; + let kmsTxSenders: HardhatEthersSigner[]; + let kmsSigners: HardhatEthersSigner[]; + let kmsNodeStorageUrls: string[]; let keyId: bigint; beforeEach(async function () { @@ -474,6 +481,8 @@ describe("KMSGeneration", function () { const fakeCrsId = getCrsId(1); describe("Before CRS generation", function () { + let kmsGeneration: KMSGeneration; + beforeEach(async function () { const fixtureData = await loadFixture(loadTestVariablesFixture); kmsGeneration = fixtureData.kmsGeneration; @@ -514,6 +523,11 @@ describe("KMSGeneration", function () { // Define the expected crsId. const crsId = getCrsId(1); + let kmsGeneration: KMSGeneration; + let owner: Wallet; + let kmsTxSenders: HardhatEthersSigner[]; + let kmsSigners: HardhatEthersSigner[]; + let kmsNodeStorageUrls: string[]; let kmsGenerationAddress: string; let eip712MessageCrsgen: EIP712; let kmsSignaturesCrsgen: string[]; @@ -628,6 +642,11 @@ describe("KMSGeneration", function () { }); describe("After CRS generation", function () { + let kmsGeneration: KMSGeneration; + let owner: Wallet; + let kmsTxSenders: HardhatEthersSigner[]; + let kmsSigners: HardhatEthersSigner[]; + let kmsNodeStorageUrls: string[]; let crsId: bigint; beforeEach(async function () { @@ -697,7 +716,7 @@ describe("KMSGeneration", function () { }); it("Should trigger key resharing for the given key ID", async function () { - const { owner, kmsGeneration } = await loadFixture(loadTestVariablesFixture); + const { owner, kmsGeneration, kmsTxSenders, kmsSigners } = await loadFixture(loadTestVariablesFixture); // Define the key digests. const serverKeyDigest: IKMSGeneration.KeyDigestStruct = { diff --git a/gateway-contracts/test/ProtocolPayment.ts b/gateway-contracts/test/ProtocolPayment.ts index 1199d7ecb2..ea2a219d6d 100644 --- a/gateway-contracts/test/ProtocolPayment.ts +++ b/gateway-contracts/test/ProtocolPayment.ts @@ -2,7 +2,7 @@ import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; import { expect } from "chai"; import { Wallet } from "ethers"; -import { GatewayConfig, ProtocolPayment, ZamaOFT } from "../typechain-types"; +import { ProtocolPayment } from "../typechain-types"; import { createRandomWallet, loadTestVariablesFixture } from "./utils"; describe("ProtocolPayment", function () { @@ -12,10 +12,7 @@ describe("ProtocolPayment", function () { // Define fake tx sender const fakeTxSender = createRandomWallet(); - let gatewayConfig: GatewayConfig; let protocolPayment: ProtocolPayment; - let mockedZamaOFT: ZamaOFT; - let mockedFeesSenderToBurnerAddress: string; let owner: Wallet; let inputVerificationPrice: bigint; let publicDecryptionPrice: bigint; @@ -27,10 +24,7 @@ describe("ProtocolPayment", function () { before(async function () { // Initialize globally used variables before each test const fixtureData = await loadFixture(loadTestVariablesFixture); - gatewayConfig = fixtureData.gatewayConfig; protocolPayment = fixtureData.protocolPayment; - mockedZamaOFT = fixtureData.mockedZamaOFT; - mockedFeesSenderToBurnerAddress = fixtureData.mockedFeesSenderToBurnerAddress; owner = fixtureData.owner; inputVerificationPrice = fixtureData.inputVerificationPrice; publicDecryptionPrice = fixtureData.publicDecryptionPrice;