From 81f648df4d12d504b589f6382ec19018800483eb Mon Sep 17 00:00:00 2001 From: Michael Kim Date: Tue, 24 Dec 2024 08:48:27 +0900 Subject: [PATCH] Change to use only temporary wallet addresses when using points --- packages/relay/src/routers/PaymentRouter.ts | 4 + packages/relay/src/utils/Errors.ts | 1 + packages/relay/test/Approval.test.ts | 27 +++- packages/relay/test/DelegatorApproval.test.ts | 27 +++- packages/relay/test/ForcedClose.test.ts | 52 ++++++- packages/relay/test/Payment.test.ts | 127 +++++++++++++++++- packages/relay/test/PaymentV2.test.ts | 127 +++++++++++++++++- packages/relay/test/TempararyAccount.test.ts | 46 +++---- packages/relay/tspec/03_Payment.ts | 8 +- 9 files changed, 378 insertions(+), 41 deletions(-) diff --git a/packages/relay/src/routers/PaymentRouter.ts b/packages/relay/src/routers/PaymentRouter.ts index 6399b65..5bbef0e 100644 --- a/packages/relay/src/routers/PaymentRouter.ts +++ b/packages/relay/src/routers/PaymentRouter.ts @@ -724,6 +724,8 @@ export class PaymentRouter { temporaryAccount = account; account = realAccount; } + } else { + return res.json(ResponseMessage.getErrorMessage("2050")); } const purchaseId: string = String(req.body.purchaseId).trim(); @@ -777,6 +779,8 @@ export class PaymentRouter { temporaryAccount = originalAccount; account = realAccount; + } else { + return res.json(ResponseMessage.getErrorMessage("2050")); } const purchaseId: string = String(req.body.purchaseId).trim(); diff --git a/packages/relay/src/utils/Errors.ts b/packages/relay/src/utils/Errors.ts index e947da7..89c1003 100644 --- a/packages/relay/src/utils/Errors.ts +++ b/packages/relay/src/utils/Errors.ts @@ -82,6 +82,7 @@ export class ResponseMessage { ["2030", "This payment cannot be closed before it is approved"], ["2033", "The task ID is not exist"], ["2040", "The status code for this task cannot be approved"], + ["2050", "Invalid payment QR code"], ["3001", "Chain Bridge functionality is not available"], ["3002", "Loyalty Bridge functionality is not available"], ["3003", "The ability to exchange points for tokens is not supported"], diff --git a/packages/relay/test/Approval.test.ts b/packages/relay/test/Approval.test.ts index fbcc687..70cd71d 100644 --- a/packages/relay/test/Approval.test.ts +++ b/packages/relay/test/Approval.test.ts @@ -61,6 +61,8 @@ describe("Test of Server", function () { const userData: IUserData[] = []; const shopData: IShopData[] = []; + let temporaryAccount: string; + interface IPurchaseData { purchaseId: string; amount: number; @@ -235,6 +237,29 @@ describe("Test of Server", function () { }; const purchaseAmount = Amount.make(purchase.amount, 18).value; + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + let paymentId: string; it("Open New Payment", async () => { const url = URI(serverURL).directory("/v1/payment/new").filename("open").toString(); @@ -244,7 +269,7 @@ describe("Test of Server", function () { amount: purchaseAmount.toString(), currency: "krw", shopId: shopData[purchase.shopIndex].shopId, - account: userData[purchase.userIndex].address, + account: temporaryAccount, }; const response = await client.post(url, params); diff --git a/packages/relay/test/DelegatorApproval.test.ts b/packages/relay/test/DelegatorApproval.test.ts index fc150b4..3feb25c 100644 --- a/packages/relay/test/DelegatorApproval.test.ts +++ b/packages/relay/test/DelegatorApproval.test.ts @@ -41,6 +41,8 @@ describe("Test of Delegator", function () { const users = deployments.accounts.users; const shops = deployments.accounts.shops; + let temporaryAccount: string; + let shopContract: Shop; let providerContract: LoyaltyProvider; let ledgerContract: Ledger; @@ -281,6 +283,29 @@ describe("Test of Delegator", function () { }; const purchaseAmount = Amount.make(purchase.amount, 18).value; + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + let paymentId: string; it("Open New Payment", async () => { const url = URI(serverURL).directory("/v1/payment/new").filename("open").toString(); @@ -290,7 +315,7 @@ describe("Test of Delegator", function () { amount: purchaseAmount.toString(), currency: "krw", shopId: shopData[purchase.shopIndex].shopId, - account: userData[purchase.userIndex].address, + account: temporaryAccount, }; const response = await client.post(url, params); diff --git a/packages/relay/test/ForcedClose.test.ts b/packages/relay/test/ForcedClose.test.ts index 10734c3..e462959 100644 --- a/packages/relay/test/ForcedClose.test.ts +++ b/packages/relay/test/ForcedClose.test.ts @@ -53,6 +53,8 @@ describe("Test of Server", function () { const userData: IUserData[] = []; const shopData: IShopData[] = []; + let temporaryAccount: string; + interface IPurchaseData { purchaseId: string; amount: number; @@ -240,6 +242,29 @@ describe("Test of Server", function () { }; const purchaseAmount = Amount.make(purchase.amount, 18).value; + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + let paymentId: string; it("Open New Payment", async () => { const url = URI(serverURL).directory("/v1/payment/new").filename("open").toString(); @@ -249,7 +274,7 @@ describe("Test of Server", function () { amount: purchaseAmount.toString(), currency: "krw", shopId: shopData[purchase.shopIndex].shopId, - account: userData[purchase.userIndex].address, + account: temporaryAccount, }; const response = await client.post(url, params); @@ -446,6 +471,29 @@ describe("Test of Server", function () { }; const purchaseAmount = Amount.make(purchase.amount, 18).value; + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + let paymentId: string; it("Open New Payment", async () => { const url = URI(serverURL).directory("/v1/payment/new").filename("open").toString(); @@ -455,7 +503,7 @@ describe("Test of Server", function () { amount: purchaseAmount.toString(), currency: "krw", shopId: shopData[purchase.shopIndex].shopId, - account: userData[purchase.userIndex].address, + account: temporaryAccount, }; const response = await client.post(url, params); diff --git a/packages/relay/test/Payment.test.ts b/packages/relay/test/Payment.test.ts index 1899d7e..4529cb9 100644 --- a/packages/relay/test/Payment.test.ts +++ b/packages/relay/test/Payment.test.ts @@ -42,6 +42,8 @@ describe("Test of Server", function () { const shops = deployments.accounts.shops; const validators = deployments.accounts.validators; + let temporaryAccount: string; + let shopContract: Shop; let providerContract: LoyaltyProvider; let ledgerContract: Ledger; @@ -335,6 +337,29 @@ describe("Test of Server", function () { assert.deepStrictEqual(response.data.data.feeRate, 0.05); }); + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + let paymentId: string; it("Endpoint POST /v1/payment/new/open", async () => { const url = URI(serverURL).directory("/v1/payment/new").filename("open").toString(); @@ -344,7 +369,7 @@ describe("Test of Server", function () { amount: amountOfLoyalty.toString(), currency: "krw", shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, - account: users[purchaseOfLoyalty.userIndex].address, + account: temporaryAccount, terminalId: "TM000001", }; const response = await client.post(url, params); @@ -437,6 +462,29 @@ describe("Test of Server", function () { assert.ok(response.data.error.message === "The status code for this payment cannot be approved"); }); + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + it("Endpoint POST /v1/payment/new/open", async () => { const url = URI(serverURL).directory("/v1/payment/new").filename("open").toString(); @@ -445,7 +493,7 @@ describe("Test of Server", function () { amount: amountOfLoyalty.toString(), currency: "krw", shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, - account: users[purchaseOfLoyalty.userIndex].address, + account: temporaryAccount, terminalId: "TM000001", }; const response = await client.post(url, params); @@ -810,6 +858,29 @@ describe("Test of Server", function () { assert.deepStrictEqual(response.data.data.feeRate, 0.05); }); + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + let paymentId: string; it("Endpoint POST /v1/payment/new/open", async () => { const url = URI(serverURL).directory("/v1/payment/new").filename("open").toString(); @@ -819,7 +890,7 @@ describe("Test of Server", function () { amount: amountOfLoyalty.toString(), currency: "krw", shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, - account: users[purchaseOfLoyalty.userIndex].address, + account: temporaryAccount, terminalId: "TM000001", }; const response = await client.post(url, params); @@ -1212,6 +1283,29 @@ describe("Test of Server", function () { assert.deepStrictEqual(response.data.data.feeRate, 0.05); }); + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + let paymentId: string; it("Endpoint POST /v1/payment/new/open", async () => { const url = URI(serverURL).directory("/v1/payment/new").filename("open").toString(); @@ -1221,7 +1315,7 @@ describe("Test of Server", function () { amount: amountOfLoyalty.toString(), currency: "krw", shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, - account: users[purchaseOfLoyalty.userIndex].address, + account: temporaryAccount, terminalId: "TM000001", }; const response = await client.post(url, params); @@ -1683,6 +1777,29 @@ describe("Test of Server", function () { assert.deepStrictEqual(response.data.data.point.balance, pointAmount.toString()); }); + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + it("Endpoint POST /v1/payment/new/open", async () => { const url = URI(serverURL).directory("/v1/payment/new").filename("open").toString(); @@ -1691,7 +1808,7 @@ describe("Test of Server", function () { amount: amountOfLoyalty.toString(), currency: "krw", shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, - account: users[purchaseOfLoyalty.userIndex].address, + account: temporaryAccount, terminalId: "TM000001", }; const response = await client.post(url, params); diff --git a/packages/relay/test/PaymentV2.test.ts b/packages/relay/test/PaymentV2.test.ts index 98cc5bc..8834a2b 100644 --- a/packages/relay/test/PaymentV2.test.ts +++ b/packages/relay/test/PaymentV2.test.ts @@ -42,6 +42,8 @@ describe("Test of Server", function () { const shops = deployments.accounts.shops; const paymentSigner = Wallet.createRandom(); + let temporaryAccount: string; + let shopContract: Shop; let providerContract: LoyaltyProvider; let ledgerContract: Ledger; @@ -327,6 +329,29 @@ describe("Test of Server", function () { assert.deepStrictEqual(response.data.data.feeRate, 0.05); }); + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + let paymentId: string; it("Endpoint POST /v2/payment/new/open", async () => { const url = URI(serverURL).directory("/v2/payment/new").filename("open").toString(); @@ -336,7 +361,7 @@ describe("Test of Server", function () { amount: amountOfLoyalty.toString(), currency: "krw", shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, - account: users[purchaseOfLoyalty.userIndex].address, + account: temporaryAccount, terminalId: "TM000001", signature: "", }; @@ -439,6 +464,29 @@ describe("Test of Server", function () { assert.ok(response.data.error.message === "The status code for this payment cannot be approved"); }); + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + it("Endpoint POST /v2/payment/new/open", async () => { const url = URI(serverURL).directory("/v2/payment/new").filename("open").toString(); @@ -447,7 +495,7 @@ describe("Test of Server", function () { amount: amountOfLoyalty.toString(), currency: "krw", shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, - account: users[purchaseOfLoyalty.userIndex].address, + account: temporaryAccount, terminalId: "TM000001", signature: "", }; @@ -827,6 +875,29 @@ describe("Test of Server", function () { assert.deepStrictEqual(response.data.data.feeRate, 0.05); }); + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + let paymentId: string; it("Endpoint POST /v2/payment/new/open", async () => { const url = URI(serverURL).directory("/v2/payment/new").filename("open").toString(); @@ -836,7 +907,7 @@ describe("Test of Server", function () { amount: amountOfLoyalty.toString(), currency: "krw", shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, - account: users[purchaseOfLoyalty.userIndex].address, + account: temporaryAccount, terminalId: "TM000001", signature: "", }; @@ -1251,6 +1322,29 @@ describe("Test of Server", function () { assert.deepStrictEqual(response.data.data.feeRate, 0.05); }); + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + let paymentId: string; it("Endpoint POST /v2/payment/new/open", async () => { const url = URI(serverURL).directory("/v2/payment/new").filename("open").toString(); @@ -1260,7 +1354,7 @@ describe("Test of Server", function () { amount: amountOfLoyalty.toString(), currency: "krw", shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, - account: users[purchaseOfLoyalty.userIndex].address, + account: temporaryAccount, terminalId: "TM000001", signature: "", }; @@ -1738,6 +1832,29 @@ describe("Test of Server", function () { assert.deepStrictEqual(response.data.data.point.balance, pointAmount.toString()); }); + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(userData[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + userData[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage( + new Wallet(userData[purchase.userIndex].privateKey), + message + ); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: userData[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + it("Endpoint POST /v2/payment/new/open", async () => { const url = URI(serverURL).directory("/v2/payment/new").filename("open").toString(); @@ -1746,7 +1863,7 @@ describe("Test of Server", function () { amount: amountOfLoyalty.toString(), currency: "krw", shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, - account: users[purchaseOfLoyalty.userIndex].address, + account: temporaryAccount, terminalId: "TM000001", signature: "", }; diff --git a/packages/relay/test/TempararyAccount.test.ts b/packages/relay/test/TempararyAccount.test.ts index 0742017..275011a 100644 --- a/packages/relay/test/TempararyAccount.test.ts +++ b/packages/relay/test/TempararyAccount.test.ts @@ -317,28 +317,6 @@ describe("Test of Server", function () { temporaryAccount = response.data.data.temporaryAccount; }); - it("Get Temporary Account", async () => { - const nonce = await ledgerContract.nonceOf(users[purchase.userIndex].address); - const message = ContractUtils.getAccountMessage( - users[purchase.userIndex].address, - nonce, - contractManager.sideChainId - ); - const signature = await ContractUtils.signMessage(users[purchase.userIndex], message); - - const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); - const response = await client.post(url, { - account: users[purchase.userIndex].address, - signature, - }); - - assert.deepStrictEqual(response.data.code, 0); - assert.ok(response.data.data !== undefined); - console.log(response.data.data.temporaryAccount); - assert.ok(response.data.data.temporaryAccount !== undefined); - temporaryAccount = response.data.data.temporaryAccount; - }); - it("Get user's balance", async () => { const url = URI(serverURL) .directory("/v1/ledger/balance/account") @@ -474,6 +452,28 @@ describe("Test of Server", function () { assert.ok(response.data.error.message === "The status code for this payment cannot be approved"); }); + it("Get Temporary Account", async () => { + const nonce = await ledgerContract.nonceOf(users[purchase.userIndex].address); + const message = ContractUtils.getAccountMessage( + users[purchase.userIndex].address, + nonce, + contractManager.sideChainId + ); + const signature = await ContractUtils.signMessage(users[purchase.userIndex], message); + + const url = URI(serverURL).directory("/v1/payment/account").filename("temporary").toString(); + const response = await client.post(url, { + account: users[purchase.userIndex].address, + signature, + }); + + assert.deepStrictEqual(response.data.code, 0); + assert.ok(response.data.data !== undefined); + console.log(response.data.data.temporaryAccount); + assert.ok(response.data.data.temporaryAccount !== undefined); + temporaryAccount = response.data.data.temporaryAccount; + }); + it("Endpoint POST /v1/payment/new/open", async () => { const url = URI(serverURL).directory("/v1/payment/new").filename("open").toString(); @@ -482,7 +482,7 @@ describe("Test of Server", function () { amount: amountOfLoyalty.toString(), currency: "krw", shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, - account: users[purchaseOfLoyalty.userIndex].address, + account: temporaryAccount, }; const response = await client.post(url, params); diff --git a/packages/relay/tspec/03_Payment.ts b/packages/relay/tspec/03_Payment.ts index ae9123b..0476a2f 100644 --- a/packages/relay/tspec/03_Payment.ts +++ b/packages/relay/tspec/03_Payment.ts @@ -169,8 +169,8 @@ export type PaymentApiSpec = Tspec.DefineApiSpec<{ */ shopId: string; /** - * Wallet address of user - * @example "0x5A3Fc8990417b3e6ddCdAE0E8039E798A609Ef84" + * Temporary wallet address of user + * @example "0xfFfFFfFF5D8F0dB23fE79F2085C4069B00000000" */ account: string; /** @@ -1009,8 +1009,8 @@ export type PaymentApiSpec = Tspec.DefineApiSpec<{ */ shopId: string; /** - * Wallet address of user - * @example "0x5A3Fc8990417b3e6ddCdAE0E8039E798A609Ef84" + * Temporary wallet address of user + * @example "0xfFfFFfFF5D8F0dB23fE79F2085C4069B00000000" */ account: string; /**