Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
test: use chain id set in process.env
Browse files Browse the repository at this point in the history
  • Loading branch information
lalexgap committed Feb 18, 2021
1 parent 90a6e35 commit c6076dc
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 50 deletions.
6 changes: 0 additions & 6 deletions packages/e2e-testing/__tests__/bad-network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,7 @@ const indexerServer = createReceiptServer([
// keys for attestation signing but no action is taken on startup
`--numAllocations ${NUM_ALLOCATIONS}`
]);

const baseConfig = defaultTestConfig({
networkConfiguration: {
chainNetworkID: process.env.CHAIN_ID
? parseInt(process.env.CHAIN_ID)
: defaultTestConfig().networkConfiguration.chainNetworkID
},
chainServiceConfiguration: {
attachChainService: false
}
Expand Down
28 changes: 16 additions & 12 deletions packages/e2e-testing/__tests__/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
PAYER_SERVER_DB_NAME,
REQUEST_CID,
RESPONSE_CID,
TEST_SUBGRAPH_ID
TEST_SUBGRAPH_ID,
CHAIN_ID
} from '../src/constants';
import {createPaymentServer, createReceiptServer} from '../src/external-server';

Expand Down Expand Up @@ -55,18 +56,21 @@ const serverArgs = [
const gatewayServer = createPaymentServer(serverArgs);
const indexerServer = createReceiptServer(serverArgs);

const baseConfig = defaultTestConfig({
networkConfiguration: {
chainNetworkID: process.env.CHAIN_ID
? parseInt(process.env.CHAIN_ID)
: defaultTestConfig().networkConfiguration.chainNetworkID
},
chainServiceConfiguration: {
attachChainService: useChain,
provider: process.env.RPC_ENDPOINT,
pk: ETHERLIME_ACCOUNTS[0].privateKey
const baseConfig = {
...defaultTestConfig({
chainServiceConfiguration: {
attachChainService: useChain,
provider: process.env.RPC_ENDPOINT,
pk: ETHERLIME_ACCOUNTS[0].privateKey
}
}),
//TODO: Work around for https://github.com/statechannels/statechannels/issues/3317
...{
networkConfiguration: {
chainNetworkID: CHAIN_ID
}
}
});
};

const payerConfig = overwriteConfigWithDatabaseConnection(baseConfig, {
database: PAYER_SERVER_DB_NAME
Expand Down
27 changes: 17 additions & 10 deletions packages/e2e-testing/chain-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,40 @@ import {ETHERLIME_ACCOUNTS, GanacheServer} from '@statechannels/devtools';
import {utils} from 'ethers';
import {deploy as deployNitro} from '@statechannels/server-wallet/lib/deployment/deploy';
import {deploy as deployGraph} from '@graphprotocol/statechannels-contracts/deployment/deploy';
import _ from 'lodash';

export default async function setup(): Promise<void> {
if (process.env.CHAIN_NETWORK_ID) {
console.log(
`CHAIN_NETWORK_ID defined as ${process.env.CHAIN_NETWORK_ID}. Assuming chain env vars are set by caller`
);
return;
}

process.env['CHAIN_NETWORK_ID'] = '9002';
process.env['GANACHE_HOST'] = '0.0.0.0';
process.env['GANACHE_PORT'] = '8545';
process.env[
'RPC_ENDPOINT'
] = `http://${process.env['GANACHE_HOST']}:${process.env['GANACHE_PORT']}`;

const ethPerAccount = utils.parseEther('100').toString();
const etherlimeAccounts = ETHERLIME_ACCOUNTS.map((account) => ({
...account,
amount: ethPerAccount
}));
const defaultServerWalletAccount = {
privateKey: process.env.ETHEREUM_PRIVATE_KEY // useful if using rinkeby account for example
? process.env.ETHEREUM_PRIVATE_KEY
: ETHERLIME_ACCOUNTS[0].privateKey,
amount: ethPerAccount
};
const accounts = _.unionBy(etherlimeAccounts, [defaultServerWalletAccount], 'privateKey');

if (!process.env.GANACHE_PORT) {
throw new Error('process.env.GANACHE_PORT must be defined');
}
const ganacheServer = new GanacheServer(parseInt(process.env.GANACHE_PORT), 1337, accounts);
const ganacheServer = new GanacheServer(
parseInt(process.env.GANACHE_PORT),
Number(process.env.CHAIN_NETWORK_ID),
etherlimeAccounts,
10_000, // timeout
10_00_000_000, // gasLimit
1 // gasPrice
);
await ganacheServer.ready();

const deployedNitroArtifacts = await deployNitro();
const deployedAttestationApp = await deployGraph();

Expand Down
9 changes: 5 additions & 4 deletions packages/e2e-testing/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {SubgraphDeploymentID} from '@graphprotocol/common-ts';
import {BigNumber, constants, utils} from 'ethers';
import {constants, utils} from 'ethers';
import * as base58 from 'bs58';
import {defaultTestConfig} from '@statechannels/server-wallet';
export const RECEIPT_SERVER_PORT = 5198;
Expand Down Expand Up @@ -29,9 +29,10 @@ export const TEST_SUBGRAPH_ID = new SubgraphDeploymentID(
export const REQUEST_CID = utils.hexZeroPad('0x1', 32);
export const RESPONSE_CID = utils.hexZeroPad('0x2', 32);
// We want to use the same chainId that we use in the payment manager/ receipt manager
export const CHAIN_ID = BigNumber.from(
defaultTestConfig().networkConfiguration.chainNetworkID
).toNumber();
export const CHAIN_ID = process.env.CHAIN_NETWORK_ID
? parseInt(process.env.CHAIN_NETWORK_ID)
: defaultTestConfig().networkConfiguration.chainNetworkID;

export const VERIFYING_CONTRACT = constants.AddressZero;

export const TEST_GRAPHQL_RESPONSE = 'OK';
Expand Down
37 changes: 22 additions & 15 deletions packages/e2e-testing/src/payment-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {BigNumber, constants, Wallet} from 'ethers';
import {BN} from '@statechannels/wallet-core';
import {
defaultTestConfig,
overwriteConfigWithDatabaseConnection
overwriteConfigWithDatabaseConnection,
ServerWalletConfig
} from '@statechannels/server-wallet';
import {Address} from '@graphprotocol/statechannels-contracts';
import {ETHERLIME_ACCOUNTS} from '@statechannels/devtools';
Expand All @@ -32,7 +33,8 @@ import {
PAYER_PRIVATE_KEY,
REQUEST_CID,
TEST_SUBGRAPH_ID,
TEST_ATTESTATION_APP_ADDRESS
TEST_ATTESTATION_APP_ADDRESS,
CHAIN_ID
} from './constants';

type MessageSenderConfig = {
Expand Down Expand Up @@ -148,6 +150,23 @@ const createTasks = (logger: Logger) => ({
logFile
}: AnyArgs & {messageSenderConfig: MessageSenderConfig}) => {
const messageSender = constructMessageSender(messageSenderConfig);
const walletConfig: ServerWalletConfig = {
...defaultTestConfig({
workerThreadAmount: Number(amountOfWorkerThreads),
databaseConfiguration: {connection: {database: pgDatabase}},
chainServiceConfiguration: {
attachChainService: !!process.env.RPC_ENDPOINT,
provider: process.env.RPC_ENDPOINT,
pk: ETHERLIME_ACCOUNTS[0].privateKey
},
loggingConfiguration: {
logDestination: logFile,
logLevel: 'debug'
}
}),
//TODO: Work around for https://github.com/statechannels/statechannels/issues/3317
networkConfiguration: {chainNetworkID: CHAIN_ID}
};

const channelManager = await ChannelManager.create({
logger: logger.child({module: 'PaymentManager'}) as any,
Expand All @@ -162,19 +181,7 @@ const createTasks = (logger: Logger) => ({
syncOpeningChannelsPollIntervalMS: 2500,
ensureAllocationsConcurrency: 10,

walletConfig: defaultTestConfig({
workerThreadAmount: Number(amountOfWorkerThreads),
databaseConfiguration: {connection: {database: pgDatabase}},
chainServiceConfiguration: {
attachChainService: !!process.env.RPC_ENDPOINT,
provider: process.env.RPC_ENDPOINT,
pk: ETHERLIME_ACCOUNTS[0].privateKey
},
loggingConfiguration: {
logDestination: logFile,
logLevel: 'debug'
}
}),
walletConfig,
backoffStrategy: {
numAttempts: 1,
initialDelay: 50
Expand Down
4 changes: 3 additions & 1 deletion packages/e2e-testing/src/receipt-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {Logger, NetworkContracts} from '@graphprotocol/common-ts';

import {createTestLogger, generateAttestations} from './utils';
import {
CHAIN_ID,
RECEIPT_PRIVATE_KEY,
RECEIPT_SERVER_PORT,
RECEIPT_SERVER_URL,
Expand Down Expand Up @@ -70,7 +71,8 @@ const commands = {
loggingConfiguration: {
logDestination: args.logFile,
logLevel: 'debug'
}
},
networkConfiguration: {chainNetworkID: CHAIN_ID}
} as const;

const receiptManager = await ReceiptManager.create(
Expand Down
4 changes: 2 additions & 2 deletions packages/payments/src/__tests__/payment-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ beforeAll(async (done) => {
defaultTestConfig({
databaseConfiguration: {connection: {database: PAYMENT_MANAGER_TEST_DB_NAME}},
networkConfiguration: {
chainNetworkID: process.env.CHAIN_ID
? parseInt(process.env.CHAIN_ID)
chainNetworkID: process.env.CHAIN_NETWORK_ID
? parseInt(process.env.CHAIN_NETWORK_ID)
: defaultTestConfig().networkConfiguration.chainNetworkID
},
chainServiceConfiguration: {
Expand Down

0 comments on commit c6076dc

Please sign in to comment.