Skip to content

Commit

Permalink
Change to use only temporary wallet addresses when using points
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Dec 23, 2024
1 parent 957752f commit 81f648d
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 41 deletions.
4 changes: 4 additions & 0 deletions packages/relay/src/routers/PaymentRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions packages/relay/src/utils/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
27 changes: 26 additions & 1 deletion packages/relay/test/Approval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ describe("Test of Server", function () {
const userData: IUserData[] = [];
const shopData: IShopData[] = [];

let temporaryAccount: string;

interface IPurchaseData {
purchaseId: string;
amount: number;
Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand Down
27 changes: 26 additions & 1 deletion packages/relay/test/DelegatorApproval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand Down
52 changes: 50 additions & 2 deletions packages/relay/test/ForcedClose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ describe("Test of Server", function () {
const userData: IUserData[] = [];
const shopData: IShopData[] = [];

let temporaryAccount: string;

interface IPurchaseData {
purchaseId: string;
amount: number;
Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand Down
Loading

0 comments on commit 81f648d

Please sign in to comment.