Skip to content

Commit

Permalink
chore(server): return network to /settings api and add tests (#657)
Browse files Browse the repository at this point in the history
* chore(server): return network to /settings api

* chore(test): add tests to /settings api
  • Loading branch information
lykalabrada authored Mar 6, 2023
1 parent 35b5ea1 commit 339b377
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/server/src/settings/SettingsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class SettingsController {
defichain: {
transferFee: this.configService.getOrThrow('defichain.transferFee') as `${number}`,
supportedTokens: supportedDfcTokens.split(',') as Array<keyof typeof SupportedDFCTokenSymbols>,
network: this.configService.getOrThrow('defichain.network'),
},
ethereum: {
transferFee: this.configService.getOrThrow('ethereum.transferFee') as `${number}`,
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/settings/SettingsInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SupportedDFCTokenSymbols, SupportedEVMTokenSymbols } from 'src/AppConfi
interface Settings {
transferFee: `${number}` | number;
supportedTokens: Array<keyof typeof SupportedEVMTokenSymbols | keyof typeof SupportedDFCTokenSymbols>;
network?: string;
}

export interface SettingsModel {
Expand Down
54 changes: 54 additions & 0 deletions apps/server/test-i9n/testing/SettingsController.i9n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { PostgreSqlContainer, StartedPostgreSqlContainer } from '@birthdayresearch/sticky-testcontainers';
import { ConfigService } from '@nestjs/config';

import { BridgeServerTestingApp } from './BridgeServerTestingApp';
import { buildTestConfig, TestingModule } from './TestingModule';

describe.only('Settings Controller Test', () => {
let testing: BridgeServerTestingApp;
let startedPostgresContainer: StartedPostgreSqlContainer;
let config: ConfigService;

beforeAll(async () => {
startedPostgresContainer = await new PostgreSqlContainer().start();

testing = new BridgeServerTestingApp(
TestingModule.register(
buildTestConfig({
defichain: { transferFee: '0.003', supportedTokens: 'BTC,ETH' },
ethereum: { transferFee: '0', supportedTokens: 'WBTC,ETH' },
startedPostgresContainer,
}),
),
);

const app = await testing.start();
config = app.get(ConfigService);
});

afterAll(async () => {
await testing.stop();
});

it('Settings service should return the correct app settings for both DeFiChain and Ethereum', async () => {
const response = await testing.inject({
method: 'GET',
url: `/settings`,
});
const settings = JSON.parse(response.payload);
const dfcSupportedTokens = config.get('SUPPORTED_DFC_TOKENS')?.split(',');
const evmSupportedTokens = config.get('SUPPORTED_EVM_TOKENS')?.split(',');

expect(settings).toMatchObject({
defichain: {
transferFee: config.get('DFC_FEE_PERCENTAGE'),
supportedTokens: dfcSupportedTokens,
network: 'Local',
},
ethereum: {
transferFee: config.get('ETH_FEE_PERCENTAGE'),
supportedTokens: evmSupportedTokens,
},
});
});
});
2 changes: 2 additions & 0 deletions apps/server/test-i9n/testing/TestingModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function buildTestConfig({
ethereum: {
rpcUrl: startedHardhatContainer?.rpcUrl ?? '',
transferFee: ethereum?.transferFee,
supportedTokens: ethereum?.supportedTokens,
contracts: {
bridgeProxy: {
address: testnet?.bridgeContractAddress ?? '',
Expand Down Expand Up @@ -81,6 +82,7 @@ type OptionalBuildTestConfigParams = {
};
ethereum: {
transferFee: string;
supportedTokens: string;
};
startedHardhatContainer: StartedHardhatNetworkContainer;
testnet: {
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface BridgeVersion {
interface Settings {
transferFee: `${number}` | number;
supportedTokens: string[];
network?: string;
}

export interface BridgeSettings {
Expand Down

0 comments on commit 339b377

Please sign in to comment.