Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to use only temporary wallet addresses when using points #405

Open
wants to merge 1 commit into
base: acccoin/v2.x.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading