Skip to content

Commit

Permalink
Allow override of CREDITCOIN_API_URL via ENV vars
Browse files Browse the repository at this point in the history
because during runtime-upgrade tests we're using `testnet.config.ts`
when running against a disconnected-node locally, however the connection
URL needs to be ws://127.0.0.1:9944.
  • Loading branch information
atodorov committed Jan 18, 2024
1 parent 76c3d7c commit 504e0a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ options replace `test` with `jest`. For example:
yarn jest src/test/collect-coins.test.ts
```

You can use `CREDITCOIN_WS_PORT` and `CREDITCOIN_METRICS_PORT` environment variables
to adjust the port values when running this test suite against a local node. That's mainly
You can use `CREDITCOIN_API_URL`, `CREDITCOIN_WS_PORT` and `CREDITCOIN_METRICS_PORT` environment variables
to adjust the some values when running this test suite against a local node. That's mainly
useful for executing the loan cycle against a Zombienet chain running locally.


Expand Down
6 changes: 5 additions & 1 deletion integration-tests/src/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ declare global {
var CREDITCOIN_CTC_CONTRACT: GluwaCreditVestingToken;
}

export const creditcoinApiUrl = (defaultUrl: string) => {
return process.env.CREDITCOIN_API_URL || defaultUrl;
};

const setup = async () => {
process.env.NODE_ENV = 'test';

Expand All @@ -39,7 +43,7 @@ const setup = async () => {

if ((global as any).CREDITCOIN_API_URL === undefined) {
const wsPort = process.env.CREDITCOIN_WS_PORT || '9944';
(global as any).CREDITCOIN_API_URL = `ws://127.0.0.1:${wsPort}`;
(global as any).CREDITCOIN_API_URL = creditcoinApiUrl(`ws://127.0.0.1:${wsPort}`);
}

if ((global as any).CREDITCOIN_METRICS_BASE === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/testnetSetup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { providers, Keyring, KeyringPair, Wallet } from 'creditcoin-js';
import { default as globalSetup } from './globalSetup';
import { default as globalSetup, creditcoinApiUrl } from './globalSetup';

const createSigner = (keyring: Keyring, who: 'lender' | 'borrower' | 'sudo'): KeyringPair => {
switch (who) {
Expand Down Expand Up @@ -38,7 +38,7 @@ const createWallet = (who: 'lender' | 'borrower') => {
};

const setup = async () => {
(global as any).CREDITCOIN_API_URL = 'wss://rpc.testnet.creditcoin.network/ws';
(global as any).CREDITCOIN_API_URL = creditcoinApiUrl('wss://rpc.testnet.creditcoin.network/ws');
(global as any).CREDITCOIN_USES_FAST_RUNTIME = false;
(global as any).CREDITCOIN_CREATE_SIGNER = createSigner;
(global as any).CREDITCOIN_CREATE_WALLET = createWallet;
Expand Down

0 comments on commit 504e0a4

Please sign in to comment.