Skip to content

Commit

Permalink
Add test mode in config
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Jun 13, 2024
1 parent a2db1e1 commit 1cece21
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/relay/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ relay:
expoAccessToken: "${EXPO_ACCESS_TOKEN}"
relayEndpoint: "${RELAY_ENDPOINT}"
encryptKey: "${RELAY_ENCRYPT_KEY}"
testMode: false

contracts:
sideChain:
Expand Down
1 change: 1 addition & 0 deletions packages/relay/config/config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ relay:
expoAccessToken: "${EXPO_ACCESS_TOKEN}"
relayEndpoint: "${RELAY_ENDPOINT}"
encryptKey: "${RELAY_ENCRYPT_KEY}"
testMode: true

contracts:
sideChain:
Expand Down
5 changes: 5 additions & 0 deletions packages/relay/src/common/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export class RelayConfig implements IRelayConfig {
public expoAccessToken: string;
public relayEndpoint: string;
public encryptKey: string;
public testMode: boolean;

constructor() {
const defaults = RelayConfig.defaultValue();
Expand All @@ -212,6 +213,7 @@ export class RelayConfig implements IRelayConfig {
this.expoAccessToken = defaults.expoAccessToken;
this.relayEndpoint = defaults.relayEndpoint;
this.encryptKey = defaults.encryptKey;
this.testMode = defaults.testMode;
}

public static defaultValue(): IRelayConfig {
Expand All @@ -232,6 +234,7 @@ export class RelayConfig implements IRelayConfig {
expoAccessToken: "",
relayEndpoint: "",
encryptKey: "",
testMode: false,
};
}

Expand All @@ -246,6 +249,7 @@ export class RelayConfig implements IRelayConfig {
if (config.expoAccessToken !== undefined) this.expoAccessToken = config.expoAccessToken;
if (config.relayEndpoint !== undefined) this.relayEndpoint = config.relayEndpoint;
if (config.encryptKey !== undefined) this.encryptKey = config.encryptKey;
if (config.testMode !== undefined) this.testMode = Boolean(config.testMode);
}
}

Expand Down Expand Up @@ -467,6 +471,7 @@ export interface IRelayConfig {
expoAccessToken: string;
relayEndpoint: string;
encryptKey: string;
testMode: boolean;
}

export interface IContractsConfig {
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/delegator/NotificationSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class NotificationSender implements INotificationSender {
this.handler.receive(to, title, body, data);
}
if (!Expo.isExpoPushToken(to)) {
if (!process.env.TESTING) logger.error(`Push token ${to} is not a valid Expo push token`);
if (!this.config.relay.testMode) logger.error(`Push token ${to} is not a valid Expo push token`);
return false;
}
const messages: ExpoPushMessage[] = [];
Expand Down
10 changes: 2 additions & 8 deletions packages/relay/src/routers/PaymentRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,10 @@ export class PaymentRouter {

let balance: BigNumber;
let paidPoint: BigNumber;
let paidToken: BigNumber;
let paidValue: BigNumber;
let feePoint: BigNumber;
let feeToken: BigNumber;
let feeValue: BigNumber;
let totalPoint: BigNumber;
let totalToken: BigNumber;
let totalValue: BigNumber;

const contract = this.contractManager.sideLedgerContract;
Expand All @@ -357,9 +354,6 @@ export class PaymentRouter {
if (totalPoint.gt(balance)) {
return res.status(200).json(ResponseMessage.getErrorMessage("1511"));
}
paidToken = BigNumber.from(0);
feeToken = BigNumber.from(0);
totalToken = BigNumber.from(0);
paidValue = BigNumber.from(amount);
feeValue = ContractUtils.zeroGWEI(paidValue.mul(feeRate).div(10000));
totalValue = paidValue.add(feeValue);
Expand Down Expand Up @@ -399,7 +393,7 @@ export class PaymentRouter {

const mobileData = await this.storage.getMobile(item.account, MobileType.USER_APP);

if (!process.env.TESTING && mobileData === undefined) {
if (!this.config.relay.testMode && mobileData === undefined) {
return res.status(200).json(ResponseMessage.getErrorMessage("2005"));
}

Expand Down Expand Up @@ -959,7 +953,7 @@ export class PaymentRouter {

const mobileData = await this.storage.getMobile(shopInfo.account, MobileType.SHOP_APP);

if (!process.env.TESTING && mobileData === undefined) {
if (!this.config.relay.testMode && mobileData === undefined) {
return res.status(200).json(ResponseMessage.getErrorMessage("2005"));
}

Expand Down
4 changes: 2 additions & 2 deletions packages/relay/src/routers/ShopRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ export class ShopRouter {

const mobileData = await this.storage.getMobile(item.account, MobileType.SHOP_APP);

if (!process.env.TESTING && mobileData === undefined) {
if (!this.config.relay.testMode && mobileData === undefined) {
return res.status(200).json(ResponseMessage.getErrorMessage("2005"));
}

Expand Down Expand Up @@ -874,7 +874,7 @@ export class ShopRouter {
/// 사용자에게 푸쉬 메세지 발송
const mobileData = await this.storage.getMobile(item.account, MobileType.SHOP_APP);

if (!process.env.TESTING && mobileData === undefined) {
if (!this.config.relay.testMode && mobileData === undefined) {
return res.status(200).json(ResponseMessage.getErrorMessage("2005"));
}

Expand Down

0 comments on commit 1cece21

Please sign in to comment.