Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions gateway-contracts/test/CiphertextCommits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 () {
Expand Down
93 changes: 50 additions & 43 deletions gateway-contracts/test/Decryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -152,6 +134,8 @@ describe("Decryption", function () {
}

describe("Deployment", function () {
let decryption: Decryption;
let owner: Wallet;
let decryptionFactory: Decryption__factory;

beforeEach(async function () {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
115 changes: 70 additions & 45 deletions gateway-contracts/test/GatewayConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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], {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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();

Expand Down
Loading
Loading