Skip to content

Commit 5a67573

Browse files
committed
refactor(gateway-contracts): extend the no-global vars pattern
1 parent 2ea1e56 commit 5a67573

File tree

1 file changed

+60
-45
lines changed

1 file changed

+60
-45
lines changed

gateway-contracts/test/GatewayConfig.ts

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,6 @@ describe("GatewayConfig", function () {
5858
const fakeTxSender = createRandomWallet();
5959
const fakeSigner = createRandomWallet();
6060

61-
let gatewayConfig: GatewayConfig;
62-
let owner: Wallet;
63-
let pauser: Wallet;
64-
let nKmsNodes: number;
65-
let kmsNodes: KmsNodeStruct[];
66-
let kmsTxSenders: HardhatEthersSigner[];
67-
let kmsSigners: HardhatEthersSigner[];
68-
let coprocessors: CoprocessorStruct[];
69-
let nCoprocessors: number;
70-
let coprocessorTxSenders: HardhatEthersSigner[];
71-
let coprocessorSigners: HardhatEthersSigner[];
72-
let custodians: CustodianStruct[];
73-
let custodianTxSenders: HardhatEthersSigner[];
74-
let custodianSigners: HardhatEthersSigner[];
75-
let highMpcThreshold: number;
76-
let highPublicDecryptionThreshold: number;
77-
let highUserDecryptionThreshold: number;
78-
let highKmsGenThreshold: number;
79-
let highCoprocessorThreshold: number;
80-
8161
async function getInputsForDeployFixture() {
8262
const fixtureData = await loadFixture(loadTestVariablesFixture);
8363
const {
@@ -97,7 +77,7 @@ describe("GatewayConfig", function () {
9777
} = fixtureData;
9878

9979
// Create KMS nodes with the tx sender and signer addresses
100-
kmsNodes = [];
80+
const kmsNodes: KmsNodeStruct[] = [];
10181
for (let i = 0; i < nKmsNodes; i++) {
10282
kmsNodes.push({
10383
txSenderAddress: kmsTxSenders[i].address,
@@ -108,7 +88,7 @@ describe("GatewayConfig", function () {
10888
}
10989

11090
// Create coprocessors with the tx sender and signer addresses
111-
coprocessors = [];
91+
const coprocessors: CoprocessorStruct[] = [];
11292
for (let i = 0; i < nCoprocessors; i++) {
11393
coprocessors.push({
11494
txSenderAddress: coprocessorTxSenders[i].address,
@@ -118,7 +98,7 @@ describe("GatewayConfig", function () {
11898
}
11999

120100
// Create custodians with the tx sender addresses
121-
custodians = [];
101+
const custodians: CustodianStruct[] = [];
122102
for (let i = 0; i < nCustodians; i++) {
123103
custodians.push({
124104
txSenderAddress: custodianTxSenders[i].address,
@@ -127,34 +107,42 @@ describe("GatewayConfig", function () {
127107
});
128108
}
129109

130-
return fixtureData;
110+
return { ...fixtureData, kmsNodes, coprocessors, custodians };
131111
}
132112

133-
before(async function () {
134-
// Initialize globally used variables before each test
135-
const fixtureData = await loadFixture(getInputsForDeployFixture);
136-
gatewayConfig = fixtureData.gatewayConfig;
137-
owner = fixtureData.owner;
138-
pauser = fixtureData.pauser;
139-
nKmsNodes = fixtureData.nKmsNodes;
140-
kmsTxSenders = fixtureData.kmsTxSenders;
141-
kmsSigners = fixtureData.kmsSigners;
142-
nCoprocessors = fixtureData.nCoprocessors;
143-
coprocessorTxSenders = fixtureData.coprocessorTxSenders;
144-
coprocessorSigners = fixtureData.coprocessorSigners;
145-
146-
highMpcThreshold = nKmsNodes;
147-
highPublicDecryptionThreshold = nKmsNodes + 1;
148-
highUserDecryptionThreshold = nKmsNodes + 1;
149-
highKmsGenThreshold = nKmsNodes + 1;
150-
highCoprocessorThreshold = nCoprocessors + 1;
151-
});
152-
153113
describe("Deployment", function () {
114+
let gatewayConfig: GatewayConfig;
115+
let owner: Wallet;
116+
let kmsNodes: KmsNodeStruct[];
117+
let coprocessors: CoprocessorStruct[];
118+
let custodians: CustodianStruct[];
119+
let nKmsNodes: number;
120+
let nCoprocessors: number;
121+
let highMpcThreshold: number;
122+
let highPublicDecryptionThreshold: number;
123+
let highUserDecryptionThreshold: number;
124+
let highKmsGenThreshold: number;
125+
let highCoprocessorThreshold: number;
154126
let proxyContract: EmptyUUPSProxyGatewayConfig;
155127
let newGatewayConfigFactory: ContractFactory;
156128

157129
beforeEach(async function () {
130+
// Load fixture data locally
131+
const fixtureData = await loadFixture(getInputsForDeployFixture);
132+
gatewayConfig = fixtureData.gatewayConfig;
133+
owner = fixtureData.owner;
134+
kmsNodes = fixtureData.kmsNodes;
135+
coprocessors = fixtureData.coprocessors;
136+
custodians = fixtureData.custodians;
137+
nKmsNodes = fixtureData.nKmsNodes;
138+
nCoprocessors = fixtureData.nCoprocessors;
139+
140+
highMpcThreshold = nKmsNodes;
141+
highPublicDecryptionThreshold = nKmsNodes + 1;
142+
highUserDecryptionThreshold = nKmsNodes + 1;
143+
highKmsGenThreshold = nKmsNodes + 1;
144+
highCoprocessorThreshold = nCoprocessors + 1;
145+
158146
// Deploy a new proxy contract for the GatewayConfig contract
159147
const proxyImplementation = await hre.ethers.getContractFactory("EmptyUUPSProxyGatewayConfig", owner);
160148
proxyContract = await hre.upgrades.deployProxy(proxyImplementation, [owner.address], {
@@ -570,17 +558,40 @@ describe("GatewayConfig", function () {
570558
});
571559

572560
describe("After deployment", function () {
561+
let gatewayConfig: GatewayConfig;
562+
let owner: Wallet;
563+
let pauser: Wallet;
564+
let nKmsNodes: number;
565+
let kmsNodes: KmsNodeStruct[];
566+
let kmsTxSenders: HardhatEthersSigner[];
567+
let kmsSigners: HardhatEthersSigner[];
568+
let nCoprocessors: number;
569+
let coprocessors: CoprocessorStruct[];
570+
let coprocessorTxSenders: HardhatEthersSigner[];
571+
let coprocessorSigners: HardhatEthersSigner[];
572+
let custodians: CustodianStruct[];
573+
let custodianTxSenders: HardhatEthersSigner[];
574+
let custodianSigners: HardhatEthersSigner[];
575+
let highMpcThreshold: number;
576+
let highPublicDecryptionThreshold: number;
577+
let highUserDecryptionThreshold: number;
578+
let highKmsGenThreshold: number;
579+
let highCoprocessorThreshold: number;
580+
573581
beforeEach(async function () {
574-
const fixture = await loadFixture(loadTestVariablesFixture);
582+
const fixture = await loadFixture(getInputsForDeployFixture);
575583
gatewayConfig = fixture.gatewayConfig;
576584
owner = fixture.owner;
577585
pauser = fixture.pauser;
578586
nKmsNodes = fixture.nKmsNodes;
587+
kmsNodes = fixture.kmsNodes;
579588
kmsTxSenders = fixture.kmsTxSenders;
580589
kmsSigners = fixture.kmsSigners;
581590
nCoprocessors = fixture.nCoprocessors;
591+
coprocessors = fixture.coprocessors;
582592
coprocessorTxSenders = fixture.coprocessorTxSenders;
583593
coprocessorSigners = fixture.coprocessorSigners;
594+
custodians = fixture.custodians;
584595
custodianTxSenders = fixture.custodianTxSenders;
585596
custodianSigners = fixture.custodianSigners;
586597

@@ -1464,6 +1475,10 @@ describe("GatewayConfig", function () {
14641475
});
14651476

14661477
describe("Pause", async function () {
1478+
let gatewayConfig: GatewayConfig;
1479+
let owner: Wallet;
1480+
let pauser: Wallet;
1481+
14671482
const fakeOwner = createRandomWallet();
14681483
const fakePauser = createRandomWallet();
14691484

0 commit comments

Comments
 (0)