diff --git a/packages/relay/config/config.yaml b/packages/relay/config/config.yaml index 3857dc86..33f10172 100644 --- a/packages/relay/config/config.yaml +++ b/packages/relay/config/config.yaml @@ -97,12 +97,12 @@ contracts: loyaltyTransferAddress: "${LOYALTY_TRANSFER_CONTRACT_ADDRESS}" tokenAddress : "${TOKEN_CONTRACT_ADDRESS}" loyaltyBridgeAddress: "${LOYALTY_BRIDGE_CONTRACT_ADDRESS}" - bridgeMainSideAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}" + bridgeAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}" mainChain: network: "bosagora_testnet" tokenAddress : "${MAIN_CHAIN_TOKEN_CONTRACT_ADDRESS}" loyaltyBridgeAddress: "${MAIN_CHAIN_LOYALTY_BRIDGE_CONTRACT_ADDRESS}" - bridgeMainSideAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}" + bridgeAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}" metrics: accounts: diff --git a/packages/relay/config/config_test.yaml b/packages/relay/config/config_test.yaml index ebc6a2d0..fad45393 100644 --- a/packages/relay/config/config_test.yaml +++ b/packages/relay/config/config_test.yaml @@ -97,12 +97,12 @@ contracts: loyaltyTransferAddress: "${LOYALTY_TRANSFER_CONTRACT_ADDRESS}" tokenAddress : "${TOKEN_CONTRACT_ADDRESS}" loyaltyBridgeAddress: "${LOYALTY_BRIDGE_CONTRACT_ADDRESS}" - bridgeMainSideAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}" + bridgeAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}" mainChain: network: "hardhat" tokenAddress : "${MAIN_CHAIN_TOKEN_CONTRACT_ADDRESS}" loyaltyBridgeAddress: "${MAIN_CHAIN_LOYALTY_BRIDGE_CONTRACT_ADDRESS}" - bridgeMainSideAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}" + bridgeAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}" metrics: accounts: diff --git a/packages/relay/package.json b/packages/relay/package.json index 0d8dfbe3..bcfd5b94 100644 --- a/packages/relay/package.json +++ b/packages/relay/package.json @@ -30,6 +30,7 @@ "test:DelegatorApproval": "TESTING=true hardhat test test/DelegatorApproval.test.ts", "test:LoyaltyTransfer": "TESTING=true hardhat test test/LoyaltyTransfer.test.ts", "test:LoyaltyBridge": "TESTING=true hardhat test test/LoyaltyBridge.test.ts", + "test:Bridge": "TESTING=true hardhat test test/Bridge.test.ts", "test:DelegatedTransfer": "TESTING=true hardhat test test/DelegatedTransfer.test.ts" }, "repository": { diff --git a/packages/relay/src/DefaultServer.ts b/packages/relay/src/DefaultServer.ts index d1a1e7a2..b3c1ad96 100644 --- a/packages/relay/src/DefaultServer.ts +++ b/packages/relay/src/DefaultServer.ts @@ -14,6 +14,7 @@ import { ContractManager } from "./contract/ContractManager"; import { RelaySigners } from "./contract/Signers"; import { INotificationEventHandler, INotificationSender, NotificationSender } from "./delegator/NotificationSender"; import { Metrics } from "./metrics/Metrics"; +import { BridgeRouter } from "./routers/BridgeRouter"; import { PhoneLinkRouter } from "./routers/PhoneLinkRouter"; import { StorePurchaseRouter } from "./routers/StorePurchaseRouter"; import { TokenRouter } from "./routers/TokenRouter"; @@ -36,7 +37,8 @@ export class DefaultServer extends WebService { public readonly etcRouter: ETCRouter; public readonly purchaseRouter: StorePurchaseRouter; public readonly tokenRouter: TokenRouter; - public readonly phonelinkRouter: PhoneLinkRouter; + public readonly phoneLinkRouter: PhoneLinkRouter; + public readonly bridgeRouter: BridgeRouter; private readonly metrics: Metrics; @@ -134,7 +136,17 @@ export class DefaultServer extends WebService { this.graph, this.relaySigners ); - this.phonelinkRouter = new PhoneLinkRouter( + this.phoneLinkRouter = new PhoneLinkRouter( + this, + this.config, + this.contractManager, + this.metrics, + this.storage, + this.graph, + this.relaySigners + ); + + this.bridgeRouter = new BridgeRouter( this, this.config, this.contractManager, @@ -184,7 +196,8 @@ export class DefaultServer extends WebService { this.etcRouter.registerRoutes(); this.purchaseRouter.registerRoutes(); this.tokenRouter.registerRoutes(); - this.phonelinkRouter.registerRoutes(); + this.phoneLinkRouter.registerRoutes(); + this.bridgeRouter.registerRoutes(); for (const m of this.schedules) await m.start(); diff --git a/packages/relay/src/common/Config.ts b/packages/relay/src/common/Config.ts index 79281a7a..3e897d3e 100644 --- a/packages/relay/src/common/Config.ts +++ b/packages/relay/src/common/Config.ts @@ -259,13 +259,13 @@ export class ContractsConfig implements IContractsConfig { loyaltyExchangerAddress: string; loyaltyTransferAddress: string; loyaltyBridgeAddress: string; - bridgeMainSideAddress: string; + bridgeAddress: string; }; public mainChain: { network: string; tokenAddress: string; loyaltyBridgeAddress: string; - bridgeMainSideAddress: string; + bridgeAddress: string; }; constructor() { @@ -283,13 +283,13 @@ export class ContractsConfig implements IContractsConfig { loyaltyExchangerAddress: defaults.sideChain.loyaltyExchangerAddress, loyaltyTransferAddress: defaults.sideChain.loyaltyTransferAddress, loyaltyBridgeAddress: defaults.sideChain.loyaltyBridgeAddress, - bridgeMainSideAddress: defaults.sideChain.bridgeMainSideAddress, + bridgeAddress: defaults.sideChain.bridgeAddress, }; this.mainChain = { network: defaults.mainChain.network, tokenAddress: defaults.mainChain.tokenAddress, loyaltyBridgeAddress: defaults.mainChain.loyaltyBridgeAddress, - bridgeMainSideAddress: defaults.mainChain.bridgeMainSideAddress, + bridgeAddress: defaults.mainChain.bridgeAddress, }; } @@ -307,13 +307,13 @@ export class ContractsConfig implements IContractsConfig { loyaltyExchangerAddress: process.env.LOYALTY_EXCHANGER_CONTRACT_ADDRESS || "", loyaltyTransferAddress: process.env.LOYALTY_TRANSFER_CONTRACT_ADDRESS || "", loyaltyBridgeAddress: process.env.LOYALTY_BRIDGE_CONTRACT_ADDRESS || "", - bridgeMainSideAddress: process.env.LOYALTY_BRIDGE_CONTRACT_ADDRESS || "", + bridgeAddress: process.env.LOYALTY_BRIDGE_CONTRACT_ADDRESS || "", }, mainChain: { network: "bosagora_mainnet", tokenAddress: process.env.TOKEN_CONTRACT_ADDRESS || "", loyaltyBridgeAddress: process.env.LOYALTY_BRIDGE_CONTRACT_ADDRESS || "", - bridgeMainSideAddress: process.env.LOYALTY_TRANSFER_CONTRACT_ADDRESS || "", + bridgeAddress: process.env.LOYALTY_TRANSFER_CONTRACT_ADDRESS || "", }, }; } @@ -337,15 +337,13 @@ export class ContractsConfig implements IContractsConfig { this.sideChain.loyaltyTransferAddress = config.sideChain.loyaltyTransferAddress; if (config.sideChain.loyaltyBridgeAddress !== undefined) this.sideChain.loyaltyBridgeAddress = config.sideChain.loyaltyBridgeAddress; - if (config.sideChain.bridgeMainSideAddress !== undefined) - this.sideChain.bridgeMainSideAddress = config.sideChain.bridgeMainSideAddress; + if (config.sideChain.bridgeAddress !== undefined) this.sideChain.bridgeAddress = config.sideChain.bridgeAddress; if (config.mainChain.network !== undefined) this.mainChain.network = config.mainChain.network; if (config.mainChain.tokenAddress !== undefined) this.mainChain.tokenAddress = config.mainChain.tokenAddress; if (config.mainChain.loyaltyBridgeAddress !== undefined) this.mainChain.loyaltyBridgeAddress = config.mainChain.loyaltyBridgeAddress; - if (config.mainChain.bridgeMainSideAddress !== undefined) - this.mainChain.bridgeMainSideAddress = config.mainChain.bridgeMainSideAddress; + if (config.mainChain.bridgeAddress !== undefined) this.mainChain.bridgeAddress = config.mainChain.bridgeAddress; } } @@ -471,13 +469,13 @@ export interface IContractsConfig { currencyRateAddress: string; loyaltyTransferAddress: string; loyaltyBridgeAddress: string; - bridgeMainSideAddress: string; + bridgeAddress: string; }; mainChain: { network: string; tokenAddress: string; loyaltyBridgeAddress: string; - bridgeMainSideAddress: string; + bridgeAddress: string; }; } diff --git a/packages/relay/src/contract/ContractManager.ts b/packages/relay/src/contract/ContractManager.ts index 894b2aff..e3dc2c40 100644 --- a/packages/relay/src/contract/ContractManager.ts +++ b/packages/relay/src/contract/ContractManager.ts @@ -29,11 +29,11 @@ export class ContractManager { private _sideLoyaltyExchangerContract: LoyaltyExchanger | undefined; private _sideLoyaltyTransferContract: LoyaltyTransfer | undefined; private _sideLoyaltyBridgeContract: LoyaltyBridge | undefined; - private _sideBridgeMainSide: Bridge | undefined; + private _sideBridge: Bridge | undefined; private _mainTokenContract: BIP20DelegatedTransfer | undefined; private _mainLoyaltyBridgeContract: Bridge | undefined; - private _mainBridgeMainSide: Bridge | undefined; + private _mainBridge: Bridge | undefined; private _sideChainProvider: ethers.providers.Provider | undefined; private _mainChainProvider: ethers.providers.Provider | undefined; @@ -80,7 +80,7 @@ export class ContractManager { this._sideLoyaltyBridgeContract = factory9.attach(this.config.contracts.sideChain.loyaltyBridgeAddress); const factory10 = await hre.ethers.getContractFactory("Bridge"); - this._sideBridgeMainSide = factory10.attach(this.config.contracts.sideChain.bridgeMainSideAddress); + this._sideBridge = factory10.attach(this.config.contracts.sideChain.bridgeAddress); await hre.changeNetwork(this.config.contracts.mainChain.network); this._mainChainProvider = hre.ethers.provider; @@ -92,7 +92,7 @@ export class ContractManager { this._mainLoyaltyBridgeContract = factory12.attach(this.config.contracts.mainChain.loyaltyBridgeAddress); const factory13 = await hre.ethers.getContractFactory("Bridge"); - this._mainBridgeMainSide = factory13.attach(this.config.contracts.mainChain.bridgeMainSideAddress); + this._mainBridge = factory13.attach(this.config.contracts.mainChain.bridgeAddress); this._mainChainId = (await this._mainChainProvider.getNetwork()).chainId; } @@ -209,10 +209,10 @@ export class ContractManager { } } - public get sideBridgeMainSide(): Bridge { - if (this._sideBridgeMainSide !== undefined) return this._sideBridgeMainSide; + public get sideBridge(): Bridge { + if (this._sideBridge !== undefined) return this._sideBridge; else { - logger.error("sideBridgeMainSide is not ready yet."); + logger.error("sideBridge is not ready yet."); process.exit(1); } } @@ -233,10 +233,10 @@ export class ContractManager { } } - public get mainBridgeMainSide(): Bridge { - if (this._mainBridgeMainSide !== undefined) return this._mainBridgeMainSide; + public get mainBridge(): Bridge { + if (this._mainBridge !== undefined) return this._mainBridge; else { - logger.error("mainBridgeMainSide is not ready yet."); + logger.error("mainBridge is not ready yet."); process.exit(1); } } diff --git a/packages/relay/src/routers/BridgeRouter.ts b/packages/relay/src/routers/BridgeRouter.ts new file mode 100644 index 00000000..73ab8e26 --- /dev/null +++ b/packages/relay/src/routers/BridgeRouter.ts @@ -0,0 +1,264 @@ +import { Config } from "../common/Config"; +import { logger } from "../common/Logger"; +import { ContractManager } from "../contract/ContractManager"; +import { ISignerItem, RelaySigners } from "../contract/Signers"; +import { Metrics } from "../metrics/Metrics"; +import { WebService } from "../service/WebService"; +import { GraphStorage } from "../storage/GraphStorage"; +import { RelayStorage } from "../storage/RelayStorage"; +import { ContractLoyaltyType } from "../types"; +import { ContractUtils } from "../utils/ContractUtils"; +import { ResponseMessage } from "../utils/Errors"; +import { Validation } from "../validation"; + +import { BigNumber, ethers } from "ethers"; +import express from "express"; +import { body, validationResult } from "express-validator"; + +export class BridgeRouter { + private web_service: WebService; + private readonly config: Config; + private readonly contractManager: ContractManager; + private readonly metrics: Metrics; + private readonly relaySigners: RelaySigners; + private storage: RelayStorage; + private graph: GraphStorage; + + constructor( + service: WebService, + config: Config, + contractManager: ContractManager, + metrics: Metrics, + storage: RelayStorage, + graph: GraphStorage, + relaySigners: RelaySigners + ) { + this.web_service = service; + this.config = config; + this.contractManager = contractManager; + this.metrics = metrics; + + this.storage = storage; + this.graph = graph; + this.relaySigners = relaySigners; + } + + private get app(): express.Application { + return this.web_service.app; + } + + /*** + * 트팬잭션을 중계할 때 사용될 서명자 + * @private + */ + private async getRelaySigner(provider?: ethers.providers.Provider): Promise { + if (provider === undefined) provider = this.contractManager.sideChainProvider; + return this.relaySigners.getSigner(provider); + } + + /*** + * 트팬잭션을 중계할 때 사용될 서명자 + * @private + */ + private releaseRelaySigner(signer: ISignerItem) { + signer.using = false; + } + + /** + * Make the response data + * @param code The result code + * @param data The result data + * @param error The error + * @private + */ + private makeResponseData(code: number, data: any, error?: any): any { + return { + code, + data, + error, + }; + } + + public registerRoutes() { + this.app.post( + "/v1/bridge/withdraw", + [ + body("account").exists().trim().isEthereumAddress(), + body("amount").exists().custom(Validation.isAmount), + body("signature") + .exists() + .trim() + .matches(/^(0x)[0-9a-f]{130}$/i), + ], + this.bridge_withdraw.bind(this) + ); + + this.app.post( + "/v1/bridge/deposit", + [ + body("account").exists().trim().isEthereumAddress(), + body("amount").exists().custom(Validation.isAmount), + body("signature") + .exists() + .trim() + .matches(/^(0x)[0-9a-f]{130}$/i), + ], + this.bridge_deposit.bind(this) + ); + } + + private async balance_account(req: express.Request, res: express.Response) { + logger.http(`GET /v1/ledger/balance/account/:account ${req.ip}:${JSON.stringify(req.params)}`); + + const errors = validationResult(req); + if (!errors.isEmpty()) { + return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() })); + } + + try { + let account: string = String(req.params.account).trim(); + if (ContractUtils.isTemporaryAccount(account)) { + const realAccount = await this.storage.getRealAccount(account); + if (realAccount === undefined) { + return res.status(200).json(ResponseMessage.getErrorMessage("2004")); + } else { + account = realAccount; + } + } + const loyaltyType = await this.contractManager.sideLedgerContract.loyaltyTypeOf(account); + if (loyaltyType === ContractLoyaltyType.POINT) { + const balance = await this.contractManager.sideLedgerContract.pointBalanceOf(account); + const value = BigNumber.from(balance); + this.metrics.add("success", 1); + return res.status(200).json( + this.makeResponseData(0, { + account, + loyaltyType, + point: { balance: balance.toString(), value: value.toString() }, + token: { balance: "0", value: "0" }, + }) + ); + } else { + const balance = await this.contractManager.sideLedgerContract.tokenBalanceOf(account); + const value = await this.contractManager.sideCurrencyRateContract.convertTokenToPoint(balance); + this.metrics.add("success", 1); + return res.status(200).json( + this.makeResponseData(0, { + account, + loyaltyType, + point: { balance: "0", value: "0" }, + token: { balance: balance.toString(), value: value.toString() }, + }) + ); + } + } catch (error: any) { + const msg = ResponseMessage.getEVMErrorMessage(error); + logger.error(`GET /v1/ledger/balance/account/:account : ${msg.error.message}`); + this.metrics.add("failure", 1); + return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error)); + } + } + + private async getDepositId(account: string): Promise { + while (true) { + const id = ContractUtils.getRandomId(account); + if (await this.contractManager.sideBridge.isAvailableDepositId(id)) return id; + } + } + + private async bridge_withdraw(req: express.Request, res: express.Response) { + logger.http(`POST /v1/bridge/withdraw ${req.ip}:${JSON.stringify(req.body)}`); + + const errors = validationResult(req); + if (!errors.isEmpty()) { + return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() })); + } + + const signerItem = await this.getRelaySigner(); + try { + const account: string = String(req.body.account).trim(); + const amount: BigNumber = BigNumber.from(req.body.amount); + const signature: string = String(req.body.signature).trim(); + + const balance = await this.contractManager.sideTokenContract.balanceOf(account); + if (balance.lt(amount)) return res.status(200).json(ResponseMessage.getErrorMessage("1511")); + + const nonce = await this.contractManager.sideTokenContract.nonceOf(account); + const message = ContractUtils.getTransferMessage( + account, + this.contractManager.sideBridge.address, + amount, + nonce, + this.contractManager.sideChainId + ); + if (!ContractUtils.verifyMessage(account, message, signature)) + return res.status(200).json(ResponseMessage.getErrorMessage("1501")); + + const tokenId = ContractUtils.getTokenId( + await this.contractManager.sideTokenContract.name(), + await this.contractManager.sideTokenContract.symbol() + ); + const depositId = await this.getDepositId(account); + const tx = await this.contractManager.sideBridge + .connect(signerItem.signer) + .depositToBridge(tokenId, depositId, account, amount, signature); + + return res.status(200).json(this.makeResponseData(0, { tokenId, depositId, amount, txHash: tx.hash })); + } catch (error: any) { + const msg = ResponseMessage.getEVMErrorMessage(error); + logger.error(`POST /v1/bridge/withdraw : ${msg.error.message}`); + this.metrics.add("failure", 1); + return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error)); + } finally { + this.releaseRelaySigner(signerItem); + } + } + + private async bridge_deposit(req: express.Request, res: express.Response) { + logger.http(`POST /v1/bridge/deposit ${req.ip}:${JSON.stringify(req.body)}`); + + const errors = validationResult(req); + if (!errors.isEmpty()) { + return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() })); + } + + const signerItem = await this.getRelaySigner(this.contractManager.mainChainProvider); + try { + const account: string = String(req.body.account).trim(); + const amount: BigNumber = BigNumber.from(req.body.amount); + const signature: string = String(req.body.signature).trim(); + + const balance = await this.contractManager.mainTokenContract.balanceOf(account); + if (balance.lt(amount)) return res.status(200).json(ResponseMessage.getErrorMessage("1511")); + + const nonce = await this.contractManager.mainTokenContract.nonceOf(account); + const message = ContractUtils.getTransferMessage( + account, + this.contractManager.mainBridge.address, + amount, + nonce, + this.contractManager.mainChainId + ); + if (!ContractUtils.verifyMessage(account, message, signature)) + return res.status(200).json(ResponseMessage.getErrorMessage("1501")); + + const tokenId = ContractUtils.getTokenId( + await this.contractManager.mainTokenContract.name(), + await this.contractManager.mainTokenContract.symbol() + ); + const depositId = await this.getDepositId(account); + const tx = await this.contractManager.mainBridge + .connect(signerItem.signer) + .depositToBridge(tokenId, depositId, account, amount, signature); + + return res.status(200).json(this.makeResponseData(0, { tokenId, depositId, amount, txHash: tx.hash })); + } catch (error: any) { + const msg = ResponseMessage.getEVMErrorMessage(error); + logger.error(`POST /v1/bridge/deposit : ${msg.error.message}`); + this.metrics.add("failure", 1); + return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error)); + } finally { + this.releaseRelaySigner(signerItem); + } + } +} diff --git a/packages/relay/src/routers/LedgerRouter.ts b/packages/relay/src/routers/LedgerRouter.ts index 2dcad89c..1a029775 100644 --- a/packages/relay/src/routers/LedgerRouter.ts +++ b/packages/relay/src/routers/LedgerRouter.ts @@ -708,8 +708,8 @@ export class LedgerRouter { return res.status(200).json(ResponseMessage.getErrorMessage("1501")); const tokenId = ContractUtils.getTokenId( - await this.contractManager.sideTokenContract.name(), - await this.contractManager.sideTokenContract.symbol() + await this.contractManager.mainTokenContract.name(), + await this.contractManager.mainTokenContract.symbol() ); const depositId = await this.getDepositId(account); const tx = await this.contractManager.mainLoyaltyBridgeContract diff --git a/packages/relay/test/Approval.test.ts b/packages/relay/test/Approval.test.ts index 5437f5e4..2228c20e 100644 --- a/packages/relay/test/Approval.test.ts +++ b/packages/relay/test/Approval.test.ts @@ -152,12 +152,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.approvalSecond = 2; diff --git a/packages/relay/test/Bridge.test.ts b/packages/relay/test/Bridge.test.ts new file mode 100644 index 00000000..2add9a08 --- /dev/null +++ b/packages/relay/test/Bridge.test.ts @@ -0,0 +1,214 @@ +import "@nomiclabs/hardhat-ethers"; +import "@nomiclabs/hardhat-waffle"; + +import { Amount } from "../src/common/Amount"; +import { Config } from "../src/common/Config"; +import { ContractManager } from "../src/contract/ContractManager"; +import { GraphStorage } from "../src/storage/GraphStorage"; +import { RelayStorage } from "../src/storage/RelayStorage"; +import { ContractUtils } from "../src/utils/ContractUtils"; +import { + CurrencyRate, + Ledger, + LoyaltyConsumer, + LoyaltyExchanger, + LoyaltyProvider, + LoyaltyTransfer, + PhoneLinkCollection, + Shop, +} from "../typechain-types"; +import { Deployments } from "./helper/Deployments"; +import { TestClient, TestServer } from "./helper/Utility"; + +import chai, { expect } from "chai"; +import { solidity } from "ethereum-waffle"; + +import * as path from "path"; +import { URL } from "url"; + +// tslint:disable-next-line:no-var-requires +const URI = require("urijs"); + +chai.use(solidity); + +describe("Test of Bridge", function () { + this.timeout(1000 * 60 * 5); + + const config = new Config(); + config.readFromFile(path.resolve(process.cwd(), "config", "config_test.yaml")); + const contractManager = new ContractManager(config); + const deployments = new Deployments(config); + + let client: TestClient; + let server: TestServer; + let storage: RelayStorage; + let serverURL: URL; + + before("Deploy", async () => { + deployments.setShopData([]); + await deployments.doDeploy(); + }); + + before("Create Config", async () => { + config.contracts.sideChain.tokenAddress = deployments.getContractAddress("TestKIOS") || ""; + config.contracts.sideChain.currencyRateAddress = deployments.getContractAddress("CurrencyRate") || ""; + config.contracts.sideChain.phoneLinkerAddress = deployments.getContractAddress("PhoneLinkCollection") || ""; + config.contracts.sideChain.ledgerAddress = deployments.getContractAddress("Ledger") || ""; + config.contracts.sideChain.shopAddress = deployments.getContractAddress("Shop") || ""; + config.contracts.sideChain.loyaltyProviderAddress = deployments.getContractAddress("LoyaltyProvider") || ""; + config.contracts.sideChain.loyaltyConsumerAddress = deployments.getContractAddress("LoyaltyConsumer") || ""; + config.contracts.sideChain.loyaltyExchangerAddress = deployments.getContractAddress("LoyaltyExchanger") || ""; + config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; + config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; + + config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; + config.contracts.mainChain.loyaltyBridgeAddress = + deployments.getContractAddress("MainChainLoyaltyBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; + + config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); + config.relay.relayEndpoint = `http://127.0.0.1:${config.server.port}`; + + client = new TestClient({ + headers: { + Authorization: config.relay.accessKey, + }, + }); + }); + + before("Create TestServer", async () => { + serverURL = new URL(`http://127.0.0.1:${config.server.port}`); + storage = await RelayStorage.make(config.database); + const graph = await GraphStorage.make(config.graph); + await contractManager.attach(); + server = new TestServer(config, contractManager, storage, graph); + }); + + before("Start TestServer", async () => { + await server.start(); + }); + + after("Stop TestServer", async () => { + await server.stop(); + await storage.dropTestDB(); + }); + + // 메인체인에서 사이드체인으로 입금 + it("Deposit token by Bridge", async () => { + const tokenId = ContractUtils.getTokenId( + await contractManager.mainTokenContract.name(), + await contractManager.mainTokenContract.symbol() + ); + const account = deployments.accounts.owner; + const amount = Amount.make(500, 18).value; + + const balance0 = await contractManager.mainTokenContract.balanceOf(account.address); + const balance1 = await contractManager.mainTokenContract.balanceOf(contractManager.mainBridge.address); + const balance2 = await contractManager.sideTokenContract.balanceOf(account.address); + + const nonce = await contractManager.mainTokenContract.nonceOf(account.address); + const message = await ContractUtils.getTransferMessage( + account.address, + contractManager.mainBridge.address, + amount, + nonce, + contractManager.mainChainId + ); + const signature = await ContractUtils.signMessage(account, message); + const response = await client.post(URI(serverURL).directory("/v1/bridge/deposit").toString(), { + account: account.address, + amount: amount.toString(), + signature, + }); + + expect(response.data.code).to.equal(0, response.data.error?.message); + expect(response.data.data).to.not.equal(undefined); + expect(response.data.data.tokenId).to.match(/^0x[A-Fa-f0-9]{64}$/i); + expect(response.data.data.depositId).to.match(/^0x[A-Fa-f0-9]{64}$/i); + expect(response.data.data.txHash).to.match(/^0x[A-Fa-f0-9]{64}$/i); + + /// Approve of Validators + await contractManager.sideBridge + .connect(deployments.accounts.bridgeValidators[0]) + .withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount); + + await contractManager.sideBridge + .connect(deployments.accounts.bridgeValidators[1]) + .withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount); + + await contractManager.sideBridge + .connect(deployments.accounts.bridgeValidators[2]) + .withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount); + /// + + expect(await contractManager.mainTokenContract.balanceOf(account.address)).to.deep.equal(balance0.sub(amount)); + expect(await contractManager.mainTokenContract.balanceOf(contractManager.mainBridge.address)).to.deep.equal( + balance1.add(amount) + ); + + const fee = await contractManager.sideBridge.getFee(tokenId); + expect(await contractManager.sideTokenContract.balanceOf(account.address)).to.deep.equal( + balance2.add(amount).sub(fee) + ); + }); + + // 사이드체인에서 메인체인으로 출금 + it("Withdrawal token by Bridge", async () => { + const tokenId = ContractUtils.getTokenId( + await contractManager.mainTokenContract.name(), + await contractManager.mainTokenContract.symbol() + ); + const account = deployments.accounts.owner; + const amount = Amount.make(200, 18).value; + + const balance0 = await contractManager.mainTokenContract.balanceOf(account.address); + const balance1 = await contractManager.mainTokenContract.balanceOf(contractManager.mainBridge.address); + const balance2 = await contractManager.sideTokenContract.balanceOf(account.address); + + const nonce = await contractManager.sideTokenContract.nonceOf(account.address); + const message = await ContractUtils.getTransferMessage( + account.address, + contractManager.sideBridge.address, + amount, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage(account, message); + const response = await client.post(URI(serverURL).directory("/v1/bridge/withdraw").toString(), { + account: account.address, + amount: amount.toString(), + signature, + }); + + expect(response.data.code).to.equal(0, response.data.error?.message); + expect(response.data.data).to.not.equal(undefined); + expect(response.data.data.tokenId).to.match(/^0x[A-Fa-f0-9]{64}$/i); + expect(response.data.data.depositId).to.match(/^0x[A-Fa-f0-9]{64}$/i); + expect(response.data.data.txHash).to.match(/^0x[A-Fa-f0-9]{64}$/i); + + /// Approve of Validators + await contractManager.mainBridge + .connect(deployments.accounts.bridgeValidators[0]) + .withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount); + + await contractManager.mainBridge + .connect(deployments.accounts.bridgeValidators[1]) + .withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount); + + await contractManager.mainBridge + .connect(deployments.accounts.bridgeValidators[2]) + .withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount); + /// + + const fee = await contractManager.mainBridge.getFee(tokenId); + expect(await contractManager.mainTokenContract.balanceOf(account.address)).to.deep.equal( + balance0.add(amount).sub(fee) + ); + expect(await contractManager.mainTokenContract.balanceOf(contractManager.mainBridge.address)).to.deep.equal( + balance1.sub(amount) + ); + // + expect(await contractManager.sideTokenContract.balanceOf(account.address)).to.deep.equal(balance2.sub(amount)); + }); +}); diff --git a/packages/relay/test/DelegatedTransfer.test.ts b/packages/relay/test/DelegatedTransfer.test.ts index 0c1a2cb2..a9a9f7bd 100644 --- a/packages/relay/test/DelegatedTransfer.test.ts +++ b/packages/relay/test/DelegatedTransfer.test.ts @@ -60,12 +60,12 @@ describe("Test of delegated transfer", function () { config.contracts.sideChain.loyaltyExchangerAddress = deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.relayEndpoint = `http://127.0.0.1:${config.server.port}`; diff --git a/packages/relay/test/DelegatorApproval.test.ts b/packages/relay/test/DelegatorApproval.test.ts index 162fd658..cf95b45d 100644 --- a/packages/relay/test/DelegatorApproval.test.ts +++ b/packages/relay/test/DelegatorApproval.test.ts @@ -152,12 +152,12 @@ describe("Test of Delegator", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.approvalSecond = 2; diff --git a/packages/relay/test/Endpoints.test.ts b/packages/relay/test/Endpoints.test.ts index 5afebfe7..a6b7f3ec 100644 --- a/packages/relay/test/Endpoints.test.ts +++ b/packages/relay/test/Endpoints.test.ts @@ -171,12 +171,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.relayEndpoint = `http://127.0.0.1:${config.server.port}`; @@ -477,12 +477,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.relayEndpoint = `http://127.0.0.1:${config.server.port}`; diff --git a/packages/relay/test/ForcedClose.test.ts b/packages/relay/test/ForcedClose.test.ts index 0efeca34..608aa940 100644 --- a/packages/relay/test/ForcedClose.test.ts +++ b/packages/relay/test/ForcedClose.test.ts @@ -144,12 +144,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.forcedCloseSecond = 5; @@ -352,12 +352,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.approvalSecond = 2; diff --git a/packages/relay/test/LoyaltyBridge.test.ts b/packages/relay/test/LoyaltyBridge.test.ts index 6ab9bd9d..f5939de5 100644 --- a/packages/relay/test/LoyaltyBridge.test.ts +++ b/packages/relay/test/LoyaltyBridge.test.ts @@ -60,12 +60,12 @@ describe("Test of LoyaltyBridge", function () { config.contracts.sideChain.loyaltyExchangerAddress = deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.relayEndpoint = `http://127.0.0.1:${config.server.port}`; diff --git a/packages/relay/test/LoyaltyTransfer.test.ts b/packages/relay/test/LoyaltyTransfer.test.ts index d875b5d3..a6ef4d0f 100644 --- a/packages/relay/test/LoyaltyTransfer.test.ts +++ b/packages/relay/test/LoyaltyTransfer.test.ts @@ -60,12 +60,12 @@ describe("Test of LoyaltyTransfer", function () { config.contracts.sideChain.loyaltyExchangerAddress = deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.relayEndpoint = `http://127.0.0.1:${config.server.port}`; diff --git a/packages/relay/test/Payment.test.ts b/packages/relay/test/Payment.test.ts index d8aafec2..7c4bdf03 100644 --- a/packages/relay/test/Payment.test.ts +++ b/packages/relay/test/Payment.test.ts @@ -187,12 +187,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.callbackEndpoint = "http://127.0.0.1:3400/callback"; @@ -657,12 +657,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.callbackEndpoint = "http://127.0.0.1:3400/callback"; @@ -1052,12 +1052,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.callbackEndpoint = "http://127.0.0.1:3400/callback"; @@ -1411,12 +1411,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.callbackEndpoint = "http://127.0.0.1:3400/callback"; @@ -1682,12 +1682,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.callbackEndpoint = "http://127.0.0.1:3400/callback"; @@ -2071,12 +2071,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.callbackEndpoint = "http://127.0.0.1:3400/callback"; @@ -2525,12 +2525,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.callbackEndpoint = "http://127.0.0.1:3400/callback"; diff --git a/packages/relay/test/Shop.test.ts b/packages/relay/test/Shop.test.ts index 19dd4de0..95f68bfe 100644 --- a/packages/relay/test/Shop.test.ts +++ b/packages/relay/test/Shop.test.ts @@ -144,12 +144,12 @@ describe("Test for Shop", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.callbackEndpoint = "http://127.0.0.1:3400/callback"; diff --git a/packages/relay/test/ShopWithdraw.test.ts b/packages/relay/test/ShopWithdraw.test.ts index 2f8d7e0b..78e051ef 100644 --- a/packages/relay/test/ShopWithdraw.test.ts +++ b/packages/relay/test/ShopWithdraw.test.ts @@ -239,12 +239,12 @@ describe("Test for Shop", () => { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.callbackEndpoint = `http://127.0.0.1:${config.server.port}/callback`; diff --git a/packages/relay/test/TempararyAccount.test.ts b/packages/relay/test/TempararyAccount.test.ts index 422ba366..f1b12e2a 100644 --- a/packages/relay/test/TempararyAccount.test.ts +++ b/packages/relay/test/TempararyAccount.test.ts @@ -188,12 +188,12 @@ describe("Test of Server", function () { deployments.getContractAddress("LoyaltyExchanger") || ""; config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || ""; config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || ""; - config.contracts.sideChain.bridgeMainSideAddress = deployments.getContractAddress("SideChainBridge") || ""; + config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || ""; config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || ""; config.contracts.mainChain.loyaltyBridgeAddress = deployments.getContractAddress("MainChainLoyaltyBridge") || ""; - config.contracts.mainChain.bridgeMainSideAddress = deployments.getContractAddress("MainChainBridge") || ""; + config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || ""; config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.callbackEndpoint = "http://127.0.0.1:3400/callback";