From 1f3b126842563dbab3ba486a542a0340b6ea7ead Mon Sep 17 00:00:00 2001 From: jiyoung Date: Mon, 13 May 2024 15:15:00 +0900 Subject: [PATCH 1/7] feat: add state rule for test. --- src/ain.ts | 2 +- src/constants.ts | 12 ++++++++++++ test/ainize.test.ts | 13 +++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/ainize.test.ts diff --git a/src/ain.ts b/src/ain.ts index 7b1ef2a..ffefe0d 100644 --- a/src/ain.ts +++ b/src/ain.ts @@ -20,7 +20,7 @@ export default class AinModule { initAin(chainId: 0 | 1) { const blockchainAPIEndpoint = getBlockChainAPIEndpoint(chainId); const blockchainEventEndpoint = getBlockChainEventEndpoint(chainId); - this.ain = new Ain(blockchainAPIEndpoint,blockchainEventEndpoint, chainId); + this.ain = new Ain('http://localhost:8081/', 'ws://localhost:5100/', chainId); } createAccount() { diff --git a/src/constants.ts b/src/constants.ts index 91bc1d8..e8b4d6f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -64,6 +64,18 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin }, }, }, + // NOTE(jiyoung): add state rule for test. + requestKey: { + ref: `${Path.app(appName).userOfService("$userAddress")}/$requestKey`, + value: { + ".rule": { + state: { + gc_max_siblings: 20, + gc_num_siblings_deleted: 10, + }, + }, + } + }, request: { ref: Path.app(appName).request("$userAddress", "$requestKey"), value: { diff --git a/test/ainize.test.ts b/test/ainize.test.ts new file mode 100644 index 0000000..001fb1c --- /dev/null +++ b/test/ainize.test.ts @@ -0,0 +1,13 @@ +import Ainize from '../src/ainize'; + +describe('ainize', () => { + it('should deploy service', async () => { + const ainize = new Ainize(0); + const privateKey = 'b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96'; + await ainize.login(privateKey); + await ainize.deploy({ + serviceName: 'TEST_SERVICE_NAME', + serviceUrl: 'TEST_SERVICE_URL', + }); + }); +}); From 10aab25620fce86869f24a7923caa0f1da192764 Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 13 May 2024 16:17:19 +0900 Subject: [PATCH 2/7] Add requestKey path function --- src/constants.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index e8b4d6f..063443b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -22,10 +22,12 @@ export const Path = { service: () => `${Path.app(appName).root()}/service`, userOfService: (userAddress: string) => `${Path.app(appName).service()}/${userAddress}`, + requestKey: (userAddress: string, requestKey: string) => + `${Path.app(appName).userOfService(userAddress)}/${requestKey}`, request: (userAddress: string, requestKey: string) => - `${Path.app(appName).userOfService(userAddress)}/${requestKey}/request`, + `${Path.app(appName).requestKey(userAddress, requestKey)}/request`, response: (userAddress: string, requestKey: string) => - `${Path.app(appName).userOfService(userAddress)}/${requestKey}/response`, + `${Path.app(appName).requestKey(userAddress, requestKey)}/response`, } }, transfer: (from: string, to: string, transferKey: string) => @@ -33,7 +35,6 @@ export const Path = { } export const defaultAppRules = (appName: string): { [type: string]: { ref: string, value: object } } => { - const rootRef = Path.app(appName).root(); return { deposit: { ref: `${Path.app(appName).depositOfUser("$userAddress")}/$transferKey`, @@ -54,7 +55,7 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin }, }, balanceHistory: { - ref: `${rootRef}/balance/$userAddress/history/$timestamp`, + ref: `${Path.app(appName).balance()}/$userAddress/history/$timestamp`, value: { ".rule": { write: @@ -66,7 +67,7 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin }, // NOTE(jiyoung): add state rule for test. requestKey: { - ref: `${Path.app(appName).userOfService("$userAddress")}/$requestKey`, + ref: Path.app(appName).requestKey("$userAddress", "$requestKey"), value: { ".rule": { state: { From e4ba126544b37ebb52c9602d5052f4ecd904a36d Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 13 May 2024 17:58:03 +0900 Subject: [PATCH 3/7] Catch exceptions and set timeout --- test/ainize.test.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/ainize.test.ts b/test/ainize.test.ts index 001fb1c..e7790b7 100644 --- a/test/ainize.test.ts +++ b/test/ainize.test.ts @@ -1,13 +1,20 @@ import Ainize from '../src/ainize'; +jest.setTimeout(25000); + describe('ainize', () => { it('should deploy service', async () => { const ainize = new Ainize(0); const privateKey = 'b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96'; - await ainize.login(privateKey); - await ainize.deploy({ - serviceName: 'TEST_SERVICE_NAME', - serviceUrl: 'TEST_SERVICE_URL', - }); + + try { + await ainize.login(privateKey); + await ainize.deploy({ + serviceName: 'TEST_SERVICE_NAME', + serviceUrl: 'TEST_SERVICE_URL', + }); + } catch (err) { + console.error(err); + } }); }); From d5364e2db8952a660850c4f1737e3d60c68e6d76 Mon Sep 17 00:00:00 2001 From: jiyoung Date: Tue, 21 May 2024 11:24:16 +0900 Subject: [PATCH 4/7] fix: fix typo. --- src/constants.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 063443b..f96358f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -65,7 +65,6 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin }, }, }, - // NOTE(jiyoung): add state rule for test. requestKey: { ref: Path.app(appName).requestKey("$userAddress", "$requestKey"), value: { @@ -90,7 +89,7 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin }, }, response: { - ref: Path.app(appName).response("userAddress", "$requestKey"), + ref: Path.app(appName).response("$userAddress", "$requestKey"), value: { ".rule": { write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isString(newData.status)" From 4c80b35c0208a2b1eab7bc77aed462bfde025b7e Mon Sep 17 00:00:00 2001 From: jiyoung Date: Tue, 21 May 2024 11:25:42 +0900 Subject: [PATCH 5/7] fix: revert input params. --- src/ain.ts | 2 +- test/ainize.test.ts | 20 -------------------- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 test/ainize.test.ts diff --git a/src/ain.ts b/src/ain.ts index ffefe0d..7ba90cb 100644 --- a/src/ain.ts +++ b/src/ain.ts @@ -20,7 +20,7 @@ export default class AinModule { initAin(chainId: 0 | 1) { const blockchainAPIEndpoint = getBlockChainAPIEndpoint(chainId); const blockchainEventEndpoint = getBlockChainEventEndpoint(chainId); - this.ain = new Ain('http://localhost:8081/', 'ws://localhost:5100/', chainId); + this.ain = new Ain(blockchainAPIEndpoint, blockchainEventEndpoint, chainId); } createAccount() { diff --git a/test/ainize.test.ts b/test/ainize.test.ts deleted file mode 100644 index e7790b7..0000000 --- a/test/ainize.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import Ainize from '../src/ainize'; - -jest.setTimeout(25000); - -describe('ainize', () => { - it('should deploy service', async () => { - const ainize = new Ainize(0); - const privateKey = 'b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96'; - - try { - await ainize.login(privateKey); - await ainize.deploy({ - serviceName: 'TEST_SERVICE_NAME', - serviceUrl: 'TEST_SERVICE_URL', - }); - } catch (err) { - console.error(err); - } - }); -}); From 0498e798b3e29ece3301aeaece6f313a9d0d2dc1 Mon Sep 17 00:00:00 2001 From: jiyoung Date: Wed, 22 May 2024 14:01:04 +0900 Subject: [PATCH 6/7] fix: add is_shallow option. --- src/ain.ts | 5 +++-- src/ainize.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ain.ts b/src/ain.ts index 7ba90cb..f4c8835 100644 --- a/src/ain.ts +++ b/src/ain.ts @@ -4,6 +4,7 @@ import { TransactionBody } from "@ainblockchain/ain-util"; import { txResult } from "./types/type"; import { Signer } from "@ainblockchain/ain-js/lib/signer/signer"; import { DefaultSigner } from "@ainblockchain/ain-js/lib/signer/default-signer" +import { GetOptions } from "@ainblockchain/ain-js/lib/types"; // NOTE(yoojin): Plz suggest a good name. export default class AinModule { @@ -89,9 +90,9 @@ export default class AinModule { return await this.ain!.db.ref(balancePath).getValue(); } - async getValue(path: string) { + async getValue(path: string, options?: GetOptions) { this.checkAinInitiated(); - return await this.ain!.db.ref(path).getValue(); + return await this.ain!.db.ref().getValue(path, options); } private async _sendTransaction(txBody: TransactionBody) { diff --git a/src/ainize.ts b/src/ainize.ts index d99bff0..ee765bd 100644 --- a/src/ainize.ts +++ b/src/ainize.ts @@ -107,7 +107,7 @@ export default class Ainize { */ async getService(serviceName: string): Promise { const servicePath = Path.app(serviceName).root(); - const serviceData = await this.ain.getValue(servicePath); + const serviceData = await this.ain.getValue(servicePath, { is_shallow: true }); if(!serviceData) { throw new Error("Service not found"); } From 08fc9b8bb4c2e3623cd1b4a70f29f6454fd5a792 Mon Sep 17 00:00:00 2001 From: akastercomcom Date: Tue, 28 May 2024 05:52:23 +0000 Subject: [PATCH 7/7] Upgrade version to 1.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9a6f8e4..9635171 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ainize-team/ainize-js", - "version": "1.2.0", + "version": "1.2.1", "main": "dist/ainize.js", "types": "dist/ainize.d.ts", "scripts": {