From 3a7a490ece2aa0c1ea89fc6e8c653921e0c34132 Mon Sep 17 00:00:00 2001 From: lalexgap Date: Wed, 6 Sep 2023 15:14:02 -0700 Subject: [PATCH 1/3] undo handling undefined These env vars get set in test/environment.d.ts --- .../test/contracts/BatchOperator/batchDeposits.test.ts | 10 +++++----- .../test/contracts/ForceMove/challenge.test.ts | 2 +- .../test/contracts/ForceMove/checkpoint.test.ts | 2 +- .../test/contracts/ForceMove/conclude.test.ts | 2 +- .../test/contracts/ForceMove/storage.test.ts | 2 +- .../test/contracts/MultiAssetHolder/deposit.test.ts | 6 +++--- .../test/contracts/MultiAssetHolder/transfer.test.ts | 2 +- .../concludeAndTransferAllAssets.test.ts | 4 ++-- .../NitroAdjudicator/transferAllAssets.test.ts | 4 ++-- .../examples/HashLockedSwap/stateIsSupported.test.ts | 6 +----- .../SingleAssetPayments/stateIsSupported.test.ts | 2 +- .../contracts/libraries/Consensus/Consensus.test.ts | 4 ++-- .../StrictTurnTaking/StrictTurnTaking.test.ts | 2 +- packages/nitro-protocol/test/test-helpers.ts | 2 +- 14 files changed, 23 insertions(+), 27 deletions(-) diff --git a/packages/nitro-protocol/test/contracts/BatchOperator/batchDeposits.test.ts b/packages/nitro-protocol/test/contracts/BatchOperator/batchDeposits.test.ts index 928c6adc5a..e8432b206b 100644 --- a/packages/nitro-protocol/test/contracts/BatchOperator/batchDeposits.test.ts +++ b/packages/nitro-protocol/test/contracts/BatchOperator/batchDeposits.test.ts @@ -16,25 +16,25 @@ const provider = getTestProvider(); const batchOperator = setupContract( provider, BatchOperatorArtifact, - process.env.BATCH_OPERATOR_ADDRESS || '' + process.env.BATCH_OPERATOR_ADDRESS ) as unknown as BatchOperator & Contract; const nitroAdjudicator = setupContract( provider, NitroAdjudicatorArtifact, - process.env.NITRO_ADJUDICATOR_ADDRESS || '' + process.env.NITRO_ADJUDICATOR_ADDRESS ) as unknown as NitroAdjudicator & Contract; const token = setupContract( provider, TokenArtifact, - process.env.TEST_TOKEN_ADDRESS || '' + process.env.TEST_TOKEN_ADDRESS ) as unknown as Token & Contract; const badToken = setupContract( provider, BadTokenArtifact, - process.env.BAD_TOKEN_ADDRESS || '' + process.env.BAD_TOKEN_ADDRESS ) as unknown as BadToken & Contract; const ETH = MAGIC_ADDRESS_INDICATING_ETH; @@ -119,7 +119,7 @@ describe('deposit_batch', () => { getChannelId({ channelNonce: getRandomNonce(description), participants: [signerAddress, counterparty], - appDefinition: consensusApp || '', + appDefinition: consensusApp, challengeDuration: 100, }) ); diff --git a/packages/nitro-protocol/test/contracts/ForceMove/challenge.test.ts b/packages/nitro-protocol/test/contracts/ForceMove/challenge.test.ts index a37be17511..03d691c420 100644 --- a/packages/nitro-protocol/test/contracts/ForceMove/challenge.test.ts +++ b/packages/nitro-protocol/test/contracts/ForceMove/challenge.test.ts @@ -97,7 +97,7 @@ async function createTwoPartySignedCountingAppState( } beforeAll(async () => { - ForceMove = setupContract(provider, ForceMoveArtifact, process.env.TEST_FORCE_MOVE_ADDRESS || ''); + ForceMove = setupContract(provider, ForceMoveArtifact, process.env.TEST_FORCE_MOVE_ADDRESS); }); // Scenarios are synonymous with channelNonce: diff --git a/packages/nitro-protocol/test/contracts/ForceMove/checkpoint.test.ts b/packages/nitro-protocol/test/contracts/ForceMove/checkpoint.test.ts index dd5f348e04..26f0106629 100644 --- a/packages/nitro-protocol/test/contracts/ForceMove/checkpoint.test.ts +++ b/packages/nitro-protocol/test/contracts/ForceMove/checkpoint.test.ts @@ -46,7 +46,7 @@ const defaultOutcome: Outcome = [ let appDefinition: string; beforeAll(async () => { - ForceMove = setupContract(provider, ForceMoveArtifact, process.env.TEST_FORCE_MOVE_ADDRESS || ''); + ForceMove = setupContract(provider, ForceMoveArtifact, process.env.TEST_FORCE_MOVE_ADDRESS); appDefinition = getCountingAppContractAddress(); }); diff --git a/packages/nitro-protocol/test/contracts/ForceMove/conclude.test.ts b/packages/nitro-protocol/test/contracts/ForceMove/conclude.test.ts index c3aee25691..00260de228 100644 --- a/packages/nitro-protocol/test/contracts/ForceMove/conclude.test.ts +++ b/packages/nitro-protocol/test/contracts/ForceMove/conclude.test.ts @@ -41,7 +41,7 @@ const outcome: Outcome = [{asset, allocations: [], assetMetadata: {assetType: 0, let appDefinition: string; beforeAll(async () => { - ForceMove = setupContract(provider, ForceMoveArtifact, process.env.TEST_FORCE_MOVE_ADDRESS || ''); + ForceMove = setupContract(provider, ForceMoveArtifact, process.env.TEST_FORCE_MOVE_ADDRESS); appDefinition = getCountingAppContractAddress(); }); diff --git a/packages/nitro-protocol/test/contracts/ForceMove/storage.test.ts b/packages/nitro-protocol/test/contracts/ForceMove/storage.test.ts index 89bce2bfb4..b7b2ee191e 100644 --- a/packages/nitro-protocol/test/contracts/ForceMove/storage.test.ts +++ b/packages/nitro-protocol/test/contracts/ForceMove/storage.test.ts @@ -9,7 +9,7 @@ import {getTestProvider, randomChannelId, setupContract} from '../../test-helper const provider = getTestProvider(); let ForceMove: Contract; beforeAll(async () => { - ForceMove = setupContract(provider, ForceMoveArtifact, process.env.TEST_FORCE_MOVE_ADDRESS || ''); + ForceMove = setupContract(provider, ForceMoveArtifact, process.env.TEST_FORCE_MOVE_ADDRESS); }); const zeroData = { diff --git a/packages/nitro-protocol/test/contracts/MultiAssetHolder/deposit.test.ts b/packages/nitro-protocol/test/contracts/MultiAssetHolder/deposit.test.ts index 9f969b4135..d2c7210d37 100644 --- a/packages/nitro-protocol/test/contracts/MultiAssetHolder/deposit.test.ts +++ b/packages/nitro-protocol/test/contracts/MultiAssetHolder/deposit.test.ts @@ -16,19 +16,19 @@ const provider = getTestProvider(); const testNitroAdjudicator = setupContract( provider, TESTNitroAdjudicatorArtifact, - process.env.TEST_NITRO_ADJUDICATOR_ADDRESS || '' + process.env.TEST_NITRO_ADJUDICATOR_ADDRESS ) as unknown as TESTNitroAdjudicator & Contract; const token = setupContract( provider, TokenArtifact, - process.env.TEST_TOKEN_ADDRESS || '' + process.env.TEST_TOKEN_ADDRESS ) as unknown as Token & Contract; const badToken = setupContract( provider, BadTokenArtifact, - process.env.BAD_TOKEN_ADDRESS || '' + process.env.BAD_TOKEN_ADDRESS ) as unknown as BadToken & Contract; const signer0 = getTestProvider().getSigner(0); // Convention matches setupContract function diff --git a/packages/nitro-protocol/test/contracts/MultiAssetHolder/transfer.test.ts b/packages/nitro-protocol/test/contracts/MultiAssetHolder/transfer.test.ts index 7a98d6c05a..3ca5d8f1b9 100644 --- a/packages/nitro-protocol/test/contracts/MultiAssetHolder/transfer.test.ts +++ b/packages/nitro-protocol/test/contracts/MultiAssetHolder/transfer.test.ts @@ -22,7 +22,7 @@ const testProvider = getTestProvider(); const testNitroAdjudicator = setupContract( testProvider, TESTNitroAdjudicatorArtifact, - process.env.TEST_NITRO_ADJUDICATOR_ADDRESS || '' + process.env.TEST_NITRO_ADJUDICATOR_ADDRESS ) as unknown as TESTNitroAdjudicator & Contract; const addresses = { diff --git a/packages/nitro-protocol/test/contracts/NitroAdjudicator/concludeAndTransferAllAssets.test.ts b/packages/nitro-protocol/test/contracts/NitroAdjudicator/concludeAndTransferAllAssets.test.ts index d1a85ccb73..58e291c89b 100644 --- a/packages/nitro-protocol/test/contracts/NitroAdjudicator/concludeAndTransferAllAssets.test.ts +++ b/packages/nitro-protocol/test/contracts/NitroAdjudicator/concludeAndTransferAllAssets.test.ts @@ -35,13 +35,13 @@ import { const testNitroAdjudicator = setupContract( getTestProvider(), TESTNitroAdjudicatorArtifact, - process.env.TEST_NITRO_ADJUDICATOR_ADDRESS || '' + process.env.TEST_NITRO_ADJUDICATOR_ADDRESS ) as unknown as TESTNitroAdjudicator & Contract; const token = setupContract( getTestProvider(), TokenArtifact, - process.env.TEST_TOKEN_ADDRESS || '' + process.env.TEST_TOKEN_ADDRESS ) as unknown as Token & Contract; const provider = getTestProvider(); diff --git a/packages/nitro-protocol/test/contracts/NitroAdjudicator/transferAllAssets.test.ts b/packages/nitro-protocol/test/contracts/NitroAdjudicator/transferAllAssets.test.ts index f8c22448e3..4a0e23af09 100644 --- a/packages/nitro-protocol/test/contracts/NitroAdjudicator/transferAllAssets.test.ts +++ b/packages/nitro-protocol/test/contracts/NitroAdjudicator/transferAllAssets.test.ts @@ -30,13 +30,13 @@ import {replaceAddressesAndBigNumberify} from '../../../src/helpers'; const testNitroAdjudicator = setupContract( getTestProvider(), TESTNitroAdjudicatorArtifact, - process.env.TEST_NITRO_ADJUDICATOR_ADDRESS || '' + process.env.TEST_NITRO_ADJUDICATOR_ADDRESS ) as unknown as TESTNitroAdjudicator & Contract; const token = setupContract( getTestProvider(), TokenArtifact, - process.env.TEST_TOKEN_ADDRESS || '' + process.env.TEST_TOKEN_ADDRESS ) as unknown as Token & Contract; const addresses = { diff --git a/packages/nitro-protocol/test/contracts/examples/HashLockedSwap/stateIsSupported.test.ts b/packages/nitro-protocol/test/contracts/examples/HashLockedSwap/stateIsSupported.test.ts index c6c78a0004..2a3ac09d11 100644 --- a/packages/nitro-protocol/test/contracts/examples/HashLockedSwap/stateIsSupported.test.ts +++ b/packages/nitro-protocol/test/contracts/examples/HashLockedSwap/stateIsSupported.test.ts @@ -58,11 +58,7 @@ const challengeDuration = 0x100; const whoSignedWhat = [1, 0]; beforeAll(async () => { - hashTimeLock = setupContract( - provider, - HashLockedSwapArtifact, - process.env.HASH_LOCK_ADDRESS || '' - ); + hashTimeLock = setupContract(provider, HashLockedSwapArtifact, process.env.HASH_LOCK_ADDRESS); }); const preImage = '0xdeadbeef'; diff --git a/packages/nitro-protocol/test/contracts/examples/SingleAssetPayments/stateIsSupported.test.ts b/packages/nitro-protocol/test/contracts/examples/SingleAssetPayments/stateIsSupported.test.ts index a5e37f9737..64b5ef0caa 100644 --- a/packages/nitro-protocol/test/contracts/examples/SingleAssetPayments/stateIsSupported.test.ts +++ b/packages/nitro-protocol/test/contracts/examples/SingleAssetPayments/stateIsSupported.test.ts @@ -47,7 +47,7 @@ beforeAll(async () => { singleAssetPayments = setupContract( provider, SingleAssetPaymentsArtifact, - process.env.SINGLE_ASSET_PAYMENTS_ADDRESS || '' + process.env.SINGLE_ASSET_PAYMENTS_ADDRESS ); }); diff --git a/packages/nitro-protocol/test/contracts/libraries/Consensus/Consensus.test.ts b/packages/nitro-protocol/test/contracts/libraries/Consensus/Consensus.test.ts index 87a40a57ed..595f8fb0dc 100644 --- a/packages/nitro-protocol/test/contracts/libraries/Consensus/Consensus.test.ts +++ b/packages/nitro-protocol/test/contracts/libraries/Consensus/Consensus.test.ts @@ -35,7 +35,7 @@ beforeAll(async () => { Consensus = setupContract( provider, testConsensusArtifact, - process.env.TEST_CONSENSUS_ADDRESS || '' + process.env.TEST_CONSENSUS_ADDRESS ) as Contract & TESTConsensus; }); @@ -65,7 +65,7 @@ describe('requireConsensus', () => { channelNonce, challengeDuration, outcome: defaultOutcome, - appDefinition: appDefinition || '', + appDefinition: appDefinition, appData: '0x', }; diff --git a/packages/nitro-protocol/test/contracts/libraries/StrictTurnTaking/StrictTurnTaking.test.ts b/packages/nitro-protocol/test/contracts/libraries/StrictTurnTaking/StrictTurnTaking.test.ts index 91527b08c2..83e495d22d 100644 --- a/packages/nitro-protocol/test/contracts/libraries/StrictTurnTaking/StrictTurnTaking.test.ts +++ b/packages/nitro-protocol/test/contracts/libraries/StrictTurnTaking/StrictTurnTaking.test.ts @@ -41,7 +41,7 @@ beforeAll(async () => { StrictTurnTaking = setupContract( provider, testStrictTurnTakingArtifact, - process.env.TEST_STRICT_TURN_TAKING_ADDRESS || '' + process.env.TEST_STRICT_TURN_TAKING_ADDRESS ) as Contract & TESTStrictTurnTaking; }); diff --git a/packages/nitro-protocol/test/test-helpers.ts b/packages/nitro-protocol/test/test-helpers.ts index 2603a60019..1ab1031ffe 100644 --- a/packages/nitro-protocol/test/test-helpers.ts +++ b/packages/nitro-protocol/test/test-helpers.ts @@ -30,7 +30,7 @@ export function setupContract( } export function getCountingAppContractAddress(): string { - return process.env.COUNTING_APP_ADDRESS || ''; + return process.env.COUNTING_APP_ADDRESS; } export const nonParticipant = ethers.Wallet.createRandom(); From f422e190abe8c37df703ee313e0bad9c556a7a51 Mon Sep 17 00:00:00 2001 From: lalexgap Date: Wed, 6 Sep 2023 15:36:37 -0700 Subject: [PATCH 2/3] include test env vars in root tsconfig This means vs code won't report linting errors for undefined env vars --- packages/nitro-protocol/tsconfig.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nitro-protocol/tsconfig.json b/packages/nitro-protocol/tsconfig.json index 28b8ce7d25..86a158d497 100644 --- a/packages/nitro-protocol/tsconfig.json +++ b/packages/nitro-protocol/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "baseUrl": "src", + "baseUrl": ".", "target": "es2018", "module": "commonjs", "strict": true, @@ -10,5 +10,5 @@ "declaration": true, "skipLibCheck": true }, - "include": ["src/index.ts", "addresses.json"] + "include": ["src/index.ts", "addresses.json", "../test/@types/environment.d.ts"] } From 76809489cb2484f8bae6efc77b4a343f9313f3ef Mon Sep 17 00:00:00 2001 From: lalexgap Date: Wed, 6 Sep 2023 16:20:52 -0700 Subject: [PATCH 3/3] undo change to base url --- packages/nitro-protocol/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nitro-protocol/tsconfig.json b/packages/nitro-protocol/tsconfig.json index 86a158d497..9425a9d56d 100644 --- a/packages/nitro-protocol/tsconfig.json +++ b/packages/nitro-protocol/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "baseUrl": ".", + "baseUrl": "src", "target": "es2018", "module": "commonjs", "strict": true,